Removing None objects from a sequence
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Mon Dec 15 20:09:58 EST 2008
Scott David Daniels:
> If you want to keep the original's method, but do it in a more Pythonic
> way, I would suggest:
>
> def deNone4(alist):
> j = 0
> for val in alist:
> if val is not None:
> alist[j] = val
> j += 1
> del alist[j :]
For my benchmarks this is also the faster version with and without
Psyco :-)
(Even it's a bit slow when given a list that has no Nones).
Bye,
bearophile
More information about the Python-list
mailing list