RE: Dict comp help

2013-01-24 Thread Joseph L. Casale
> >>> 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/

Re: Dict comp help

2013-01-24 Thread Rob Day
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(

RE: Dict comp help

2013-01-24 Thread Leonard, Arah
> 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': '

Re: Dict comp help

2013-01-24 Thread Peter Otten
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', '

Re: Dict comp help

2013-01-24 Thread Oscar Benjamin
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

Re: Dict comp help

2013-01-24 Thread Dave Angel
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': '

Dict comp help

2013-01-24 Thread Joseph L. Casale
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': 'dd', 'b': 'ee'