Dict comprehension help
Joseph L. Casale
jcasale at activenetwerx.com
Thu Dec 6 10:32:19 EST 2012
>You could put the loop into a helper function, but if you are looping
>through the same my_list more than once why not build a lookup table
>
>my_dict = {d["key"]: d for d in my_list}
>
>and then find the required dict with
>
>my_dict[value]
I suppose, what I failed to clarify was that for each list of dicts, I may
only extract out one (maybe two) dicts, but I have several to do this for.
The tidy one-liners make for populating the vars in __init__ nice and clean.
Much appreciated guys, thanks!
jlc
More information about the Python-list
mailing list