How I can get rid of None values in dictionary? Python
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
11:43 UTC
Read the original article
Hit count: 325
python
Something like:
for (a,b) in kwargs.iteritems():
if not b : del kwargs[a]
This code raise exception because changing of dictionary when itering...
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