[Tutor] Yet another list comprehension question

Jordan Greenberg greenbergj at wit.edu
Fri Mar 2 17:10:04 CET 2007

Smith, Jeff wrote:
> I find a common thing to do is
> l = list()
> for i in some-iterator:
>     if somefum(i) != list:
>     	l.append(somefun(i))

How about using the same condition you do in the if? Like:
l=[somefun(i) for i in some-iterator if not type(somefun(i)) is list]


More information about the Tutor mailing list