newbe how to read in a string?
Alex Martelli
aleaxit at yahoo.com
Fri Mar 23 12:31:55 EST 2001
"Chris Gonnerman" <chris.gonnerman at usa.net> wrote in message
news:mailman.985355670.6600.python-list at python.org...
[snip]
> import string
> seq = string.split(a, ",")
> for i in range(1, len(seq)): # this skips the 0 index,
> seq[i] = float(seq) # which needs to stay a string.
>
> In Python 2.0 the code might be shorter, using string methods and list
> comprehension, but I personally prefer the "old way" myself.
The 'old way' would be
seq = map(float, string.split(a, ','))
and it still works fine of course, though I'd rather spell it
seq = map(float, ','.split(a))
List comprehensions are great, but when you DO want to get
map's primary job (applying an already-existing function
to parameter sequences) map is still best (with list
comprehension, you can avoid using _lambda_ just in order
to be able to use map -- I think eschewing lambda makes
your code clearer, but maybe that's just me).
Alex
More information about the Python-list
mailing list