How I can get rid of None values in dictionary?
Posted
by Vojtech R.
on Stack Overflow
See other posts from Stack Overflow
or by Vojtech R.
Published on 2010-03-30T11:27:00Z
Indexed on
2010/03/30
12:43 UTC
Read the original article
Hit count: 436
Something like:
for (a,b) in kwargs.iteritems():
if not b : del kwargs[a]
This code raise exception because changing of dictionary when iterating.
I discover only non pretty solution with another dictionary:
res ={}
res.update((a,b) for a,b in kwargs.iteritems() if b is not None)
Thanks
© Stack Overflow or respective owner