stdazi:

The RE-based solutions look good. Here is a pair of alternative
solutions:

s1 = 'foo bar- blah/hm.lala'
r1 = ['foo', 'bar', 'blah', 'hm', 'lala']

s2 = 'foo////bbbar.. xyz'
r2 = ['foo', 'bbbar', 'xyz']

table = "".join((c if c.isalpha() else " " for c) in map(chr,
range(256)))
#table = "".join((" "+c)[c.isalpha()] for c in map(chr, range(256))) #
Py2.4
print s1.translate(table).split()
print s2.translate(table).split()

Or:

from itertools import groupby
print ["".join(gr) for he,gr in groupby(s1, str.isalpha) if he]
print ["".join(gr) for he,gr in groupby(s2, str.isalpha) if he]

Bye,
bearophile

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to