newby question: Splitting a string - separator
Tim Roberts
timr at probo.com
Sat Dec 10 03:16:18 EST 2005
James Stroud <jstroud at mbi.ucla.edu> wrote:
>
>The one I like best goes like this:
>
>py> data = "Guido van Rossum Tim Peters Thomas Liesner"
>py> names = [n for n in data.split() if n]
>py> names
>['Guido', 'van', 'Rossum', 'Tim', 'Peters', 'Thomas', 'Liesner']
>
>I think it is theoretically faster (and more pythonic) than using regexes.
But it is slower than this, which produces EXACTLY the same (incorrect)
result:
data = "Guido van Rossum Tim Peters Thomas Liesner"
names = data.split()
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list