On Thu, Dec 17, 2009 at 19:49, Hugo Arts <[email protected]> wrote:
> Probably easiest to use a regular expression to fix that particular
> thing, as in:
>
> import re
> mult_space = re.compile(r'\s+')
> def prestrings2list(a_str):
> return [re.sub(mult_space, ' ', x).strip() for x in a_str.split(',')]
>
> Hugo
That's perfect, Hugo!
========================================
a_str = "blender , synthetic DNA, myrmecology, fungi, quorum sensing,
theoretical physic's, reason, love, hope, virtual reality, google
operating system, space, life, mystery, truth's, universe, immortality,
strangeness, fun ,living, hope, eternity, knowledge, Egyptian secrets of the
dead, n-space, hyper-time , theory of everything, light, nuclear theory,
particle theory, myrmec, self replicating RNA, MMOG, MMOR%PG,
symbiosis,Black's Plague, selddir, Da Vinci, Newton, Archimedes, Cantor7,
Leibnitz, myrmecology"
def prestrings2list(a_str):
import re
mult_space = re.compile(r'\s+')
return [re.sub(mult_space, ' ', x).strip() for x in a_str.split(',')]
lst = prestrings2list(a_str)
print(lst)
=================================================
OUTPUT
['blender', 'synthetic DNA', 'myrmecology', 'fungi', 'quorum sensing',
"theoretical physic's", 'reason', 'love', 'hope', 'virtual reality', 'google
operating system', 'space', 'life', 'mystery', "truth's", 'universe',
'immortality', 'strangeness', 'fun', 'living', 'hope', 'eternity',
'knowledge', 'Egyptian secrets of the dead', 'n-space', 'hyper-time',
'theory of everything', 'light', 'nuclear theory', 'particle theory',
'myrmec', 'self replicating RNA', 'MMOG', 'MMOR%PG', 'symbiosis', "Black's
Plague", 'selddir', 'Da Vinci', 'Newton', 'Archimedes', 'Cantor7',
'Leibnitz', 'myrmecology']
Now for a better function name, and a proper docstring. Anyone?
Dick
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor