python - How do I remove key values in a dictionary? -


python language.

i know how remove keys in dictionary, example:

def remove_zeros(dict)     dict = {'b': 0, 'c': 7, 'a': 1, 'd': 0, 'e': 5}     del dict[5]     return dict 

i want know how remove values 0 dictionary , sort keys alphabetically. using example above, i'd want ['a', 'c', 'e'] result, eliminating key values b , d completely.

to sort use dict.sort() ?

is there special function must use?

sorted(k (k, v) in d.iteritems() if v) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -