> >>> data = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c':
> >>> 'ff'}]
> >>> {d["a"]: d["c"] for d in data}
> {'xx': 'zz', 'dd': 'ff'}
Priceless,
That is exactly what I needed, for which I certainly over complicated!
Thanks everyone!
jlc
--
http://mail.python.org/mailman/
On 24 January 2013 21:11, Oscar Benjamin wrote:
l = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}]
dict(d.values()[:2] for d in l)
> {'xx': 'zz', 'dd': 'ff'}
Python doesn't guarantee any ordering of items in a dictionary; {'a':
'xx', 'b': 'yy', 'c': 'zz'}.values(
> Hi,
> Slightly different take on an old problem, I have a list of dicts, I need to
> build one dict from this based on two values from each dict in the list. Each
> of the dicts in the list have similar key names, but values of course differ.
>
>
> [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': '
Joseph L. Casale wrote:
> Slightly different take on an old problem, I have a list of dicts, I need
> to build one dict from this based on two values from each dict in the
> list. Each of the dicts in the list have similar key names, but values of
> course differ.
>
>
> [{'a': 'xx', 'b': 'yy', '
On 24 January 2013 20:58, Joseph L. Casale wrote:
> Hi,
> Slightly different take on an old problem, I have a list of dicts, I need to
> build one dict
> from this based on two values from each dict in the list. Each of the dicts
> in the list have
> similar key names, but values of course diffe
On 01/24/2013 03:58 PM, Joseph L. Casale wrote:
Hi,
Slightly different take on an old problem, I have a list of dicts, I need to
build one dict
from this based on two values from each dict in the list. Each of the dicts in
the list have
similar key names, but values of course differ.
[{'a': '