Dict comprehension help
Joseph L. Casale
jcasale at activenetwerx.com
Wed Dec 5 23:38:08 EST 2012
> {k: v for d in my_list if d['key'] == value for (k, v) in d.items()}
Ugh, had part of that backwards:) Nice!
> However, since you say that all dicts have a unique value for
> z['key'], you should never need to actually merge two dicts, correct?
> In that case, why not just use a plain for loop to search for the
> dict?
The reason is that I need several of these in an init function and they
stack up nicely where as the loops get unruly in length, but I don't
disagree.
More information about the Python-list
mailing list