[Tutor] Amazed

Jacob S. keridee at jayco.net
Fri Nov 12 04:27:18 CET 2004


    I'm amazed that several people are having trouble with list
comprehensions. I must think in that style or something. I've come up with
odd uses for them. This one threw me for a while...

newlist = []
powers = []
a = 'x**2+sin(x)+2*x'
a = a.split("+")
powers = [newlist.append(x) for x in a if x.count('**') >= 1]
print powers

#Code yields


    Since this is embeded deep in sloppy code, it took me a bit to realize
that I was really wanting newlist.

>>> print newlist

Just thought I'd share an odd usage of list comprehensions with you all.
Jacob Schmidt

More information about the Tutor mailing list