> I'm relatively new to python but I already noticed that many lines of > python code can be simplified to a oneliner by some clever coder. As > the topics says, I'm trying to split lines like this : > > 'foo bar- blah/hm.lala' -> [foo, bar, blah, hm, lala] > > 'foo////bbbar.. xyz' -> [foo, bbbar, xyz] > > obviously a for loop catching just chars could do the trick, but I'm > looking for a more elegant way. Anyone can help?
A simple regular expression would work: >>> import re >>> s = 'foo bar- blah/hm.lala' >>> re.findall(r"\w+",s) ['foo', 'bar', 'blah', 'hm', 'lala'] -- http://mail.python.org/mailman/listinfo/python-list