Removing None objects from a sequence

Filip Gruszczyński gruszczy at gmail.com
Fri Dec 12 04:18:35 EST 2008


Hi!

I would like to iterate over a sequence nad ignore all None objects.
The most obvious way is explicitly checking if element is not None,
but it takes too much space. And I would like to get something faster.
I can use
[ sth for sth in self.__sth if not sth is None ], but I don't know if
that's the best way. I checked itertools, but the only thing that
seemed ok, was ifilter - this requires seperate function though, so
doesn't seem too short. How can I get it the shortest and fastest way?

-- 
Filip Gruszczyński


More information about the Python-list mailing list