![]() |
RE: Dict comprehension help
> {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. |
| All times are GMT. The time now is 01:00 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.