Looping over a list question

Leif K-Brooks eurleif at ecritters.biz
Tue Oct 3 21:55:12 CEST 2006


Tim Williams wrote:
> Maybe
> 
>>>> def myfunc(txt):
> ...     print txt
> ...    
>>>> datafiles = ['1.txt','2.txt','3.txt','4.tst']
>>>> null = [myfunc(i) for i in datafiles if '.txt' in i]
> 1.txt
> 2.txt
> 3.txt

Ew. List comprehensions with side effects are very icky.



More information about the Python-list mailing list