Re: newby question: Splitting a string - separator

2005-12-10 Thread Fredrik Lundh
James Stroud wrote: > >> 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 > >

Re: newby question: Splitting a string - separator

2005-12-10 Thread Tim Roberts
James Stroud <[EMAIL PROTECTED]> 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 fast

Re: newby question: Splitting a string - separator

2005-12-09 Thread James Stroud
Steven D'Aprano wrote: > On Fri, 09 Dec 2005 18:02:02 -0800, James Stroud wrote: > > >>Thomas Liesner wrote: >> >>>Hi all, >>> >>>i am having a textfile which contains a single string with names. >>>I want to split this string into its records an put them into a list. >>>In "normal" cases i would

Re: newby question: Splitting a string - separator

2005-12-09 Thread Steven D'Aprano
On Fri, 09 Dec 2005 18:02:02 -0800, James Stroud wrote: > Thomas Liesner wrote: >> Hi all, >> >> i am having a textfile which contains a single string with names. >> I want to split this string into its records an put them into a list. >> In "normal" cases i would do something like: >> >> >>>#!

Re: newby question: Splitting a string - separator

2005-12-09 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Thomas Liesner wrote: >> Hi all, >> >> i am having a textfile which contains a single string with names. >> I want to split this string into its records an put them into a list. >> In "normal" cases i would do something like: >> >>> #!/usr/bin/python >>> inp = open("file"

Re: newby question: Splitting a string - separator

2005-12-09 Thread James Stroud
Kent Johnson wrote: > James Stroud 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 t

Re: newby question: Splitting a string - separator

2005-12-09 Thread bonono
Thomas Liesner wrote: > Hi all, > > i am having a textfile which contains a single string with names. > I want to split this string into its records an put them into a list. > In "normal" cases i would do something like: > > > #!/usr/bin/python > > inp = open("file") > > data = inp.read() > > name

Re: newby question: Splitting a string - separator

2005-12-09 Thread Tim Peters
[James Stroud] >> 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

Re: newby question: Splitting a string - separator

2005-12-09 Thread Kent Johnson
James Stroud 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 p

Re: newby question: Splitting a string - separator

2005-12-09 Thread James Stroud
Thomas Liesner wrote: > Hi all, > > i am having a textfile which contains a single string with names. > I want to split this string into its records an put them into a list. > In "normal" cases i would do something like: > > >>#!/usr/bin/python >>inp = open("file") >>data = inp.read() >>names =

Re: newby question: Splitting a string - separator

2005-12-08 Thread Jim
Hi Tom, > a regex for "more than one whitespace". RegEx for whitespace is \s, but > what would i use for "more than one"? \s+? For more than one, I'd use \s\s+ -Jim -- http://mail.python.org/mailman/listinfo/python-list

Re: newby question: Splitting a string - separator

2005-12-08 Thread Noah
Thomas Liesner wrote: > ... > The only thing i can rely on, ist that the > recordseparator is always more than a single whitespace. > > I thought of something like defining the separator for split() by using > a regex for "more than one whitespace". RegEx for whitespace is \s, but > what would i

Re: newby question: Splitting a string - separator

2005-12-08 Thread Michael Spencer
Thomas Liesner wrote: > Hi all, > > i am having a textfile which contains a single string with names. > I want to split this string into its records an put them into a list. > In "normal" cases i would do something like: > >> #!/usr/bin/python >> inp = open("file") >> data = inp.read() >> names =

newby question: Splitting a string - separator

2005-12-08 Thread Thomas Liesner
Hi all, i am having a textfile which contains a single string with names. I want to split this string into its records an put them into a list. In "normal" cases i would do something like: > #!/usr/bin/python > inp = open("file") > data = inp.read() > names = data.split() > inp.close() The probl