[Tutor] parsing a blank-separated string into a list

Daniel Coughlin kauphlyn@speakeasy.org
Wed, 6 Jun 2001 12:14:45 -0700 (PDT)


Hey Eugene,

Long time since Planeria, eh?

try
>>jmevalue = ' 10 11 C 9.13 ect '
>>jmelist = jmevalue.split(' ')
>>jmelist
['10', '11', 'C', '9.13', etc]



On Wed, 6 Jun 2001, Eugene Leitl wrote:

>
> Assuming, I have a string like this (produced by the JME applet,
> encoding a molecule I entered):
>
> 10 11 C 9.13 -8.85 C 10.34 -8.15 C 7.92 -8.15 C 10.34 -6.75 C 7.92 -6.75 C
> 8.43 -3.89 C 9.83 -3.89 C 8.00 -5.23 C 10.26 -5.23 C+ 9.13 -6.05 1 2 2 1 3
> 1 2 4 1 3 5 2 4 10 2 5 10 1 6 7 1 6 8 1 7 9 1 8 10 1 9 10 1
>
> And want to turn it into a list like this:
>
> [10, 11, C, 9.13 ... ]
>
> How do I do it?
>
> jmelist = map(None, jmevalue) produces
>
> [1, 0, 1, 1, C, ...], whereas I want the blank-separted atoms.
>
> Is there an idiom for that? (I mean, it's of course possible to do it by
> hand, but it's not Python Zen).
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>