print is not a function

Karl Scalet news at yebu.de
Thu Oct 9 08:15:32 EDT 2003


Hi Marc,

Marc Boeren wrote:

> Hi,
> 
> 
>>>    for x in my_list: print x
>>
>>I am yet convinced, this is the best solution for printing a 
>>simple list
> 
> 
>>But what, if I have a condition on the list.
>>Everyone tries to keep me away from list-comprehension :-)
> 
> 
> sortof: how about
> 
> for goodx in [x for x in my_list if x.startswith('QA')]: print goodx

Yeah, I like that.
That will become my favorite, thanks
(mind if I replace goodx with x :-)

Reading over the thread again, I found that Alex suggested some
similar contruct, I apologize for having overseen that the first
time. (Pls use red ink next time:-)

> 
> 
> [listcomprehensions side-effects]
> 
>>Maybe I do not understand potential problems from side-effects, which
>>I do not see in *this* case.
> 
> 
> I don't think there are really any problems with just using the side-effects
> of a list comprehension, it's just that the casual observer of the code will
> have to look a bit better before noticing that it _is_ about the
> side-effects: 'for x in my_list: print x' is very clear in exactly what it
> performs.
>

yes

> Cheerio, Marc.
> 

Ciao, Karl





More information about the Python-list mailing list