I've read AMK's RE HowTo but I think I'm missing something obvious when it comes to substitutions. Any offers for a more elegant solution to the program below gratefully received. TIA Paul ------------------------ import string,re directors = ['Prof A B Looney','Dr C D E Ftang','Ms H I J K Biscuit Barrel'] # I want no spaces between the initials # Prof AB Looney # Dr CDE Ftang # Ms HIJK Biscuit Barrel match_initials = re.compile(r'([A-Z] )+') print for director in directors: s = match_initials.search(director) inits = s.group(0) new_inits = string.replace(inits,' ','') new_director = string.replace(director,inits,new_inits + ' ') print director,new_director -- -- The Library, Tyndall Avenue, Univ. of Bristol, Bristol, BS8 1TJ, UK E-mail: Paul.Browning at bristol.ac.uk URL: http://www.bris.ac.uk/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4