[Tutor] Amazed

Kent Johnson kent37 at tds.net
Fri Nov 12 04:37:01 CET 2004


Jacob S. wrote:
> newlist = []
> powers = []
> a = 'x**2+sin(x)+2*x'
> a = a.split("+")
> powers = [newlist.append(x) for x in a if x.count('**') >= 1]
This is bizarre, to append to another list instead of just letting the 
list comprehension do its thing! It could be
powers = [x for x in a if x.count('**') >= 1]

or how about
powers = [x for x in a if '**' in x]

Kent


More information about the Tutor mailing list