String to List Question
Philip Semanchuk
philip at semanchuk.com
Thu Jul 2 18:15:03 EDT 2009
On Jul 2, 2009, at 6:05 PM, Hanna Michelsen wrote:
> Hi,
>
> I am brand new to python and I love it, but I've been having some
> trouble
> with a file parser that I've been working on. It contains lines that
> start
> with a name and then continue with names, nicknames and phone
> numbers of
> people associated with that name. I need to create a list of the
> names of
> people associated with each singular person (the first name in each
> line).
> Each name/phone number is separated by a tab but if someone doesn't
> have a
> nickname there are two tabs between their name and number.
>
> I've been trying to figure out how to test for two tabs, skip over
> these
> people and move onto the next name but I just can't figure out how
> that will
> work in python.
>
> Any help would be greatly appreciated!
Hi Hanna,
Are you familiar with a string's split() function? It sounds like just
what you need.
http://docs.python.org/library/stdtypes.html#str.split
HTH
Philip
More information about the Python-list
mailing list