Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37634

Re: Dict comp help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.064
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'subject:help': 0.07; 'dict': 0.09; 'cc:addr:python-list': 0.10; 'cases': 0.15; 'slightly': 0.15; "{'a':": 0.16; 'wrote:': 0.17; '>>>': 0.18; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'values': 0.26; 'message-id:@mail.gmail.com': 0.27; 'handle': 0.33; 'anyone': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'clear': 0.35; 'problem,': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'list.': 0.35; 'really': 0.36; 'but': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'build': 0.39; 'your': 0.60; 'different': 0.63; 'insight': 0.71; '2013': 0.84; 'oscar': 0.84; 'subject:comp': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=TnaJwMgBAP8h9rzwltE0KZHMalxLujEYzQnFQQVpT68=; b=C6ezFqBENbKmM79BeMz9jEOoKRLofCJf5bZ7ysF+C5U9XsoUwDm+vqhgXswXccJ5oI BvWnXXWzkaPL4U6TAix+/8cIMh2j0w8hiW11DgEdgU7xjXijZ41+HxDHUxwKSeVA4t7M uYM/ygI39c6U9mD8yYBjsaAq2cWqK6yY6eu7Fbon5A08074/T2HO1NlPGq6al7EyFqF8 NXTiUlFA9BI0qwcSyOzvGfDMJUk/D7REFQBMGdlq9p/zhSY5im3Z8gXl0PWt9mrfspVi YVwCUBArjWo3f5lYLHWjtIEk11UpKaTxU7ZemVSVjg7lHHpTNERhy5dmYmAJgAwtDM1u o3Gw==
MIME-Version 1.0
X-Received by 10.152.109.210 with SMTP id hu18mr3103807lab.12.1359061892981; Thu, 24 Jan 2013 13:11:32 -0800 (PST)
In-Reply-To <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com>
References <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com>
Date Thu, 24 Jan 2013 21:11:32 +0000
Subject Re: Dict comp help
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To "Joseph L. Casale" <jcasale@activenetwerx.com>
Content-Type text/plain; charset=ISO-8859-1
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1016.1359061894.2939.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359061894 news.xs4all.nl 6894 [2001:888:2000:d::a6]:46080
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37634

Show key headers only | View raw


On 24 January 2013 20:58, Joseph L. Casale <jcasale@activenetwerx.com> 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': 'xx', 'b': 'yy', 'c': 'zz'},  {'a': 'dd', 'b': 'ee', 'c': 'ff'}]
>
>
> { 'xx': 'zz', 'dd': 'ff'}
>
>
> Anyone have insight on how to pull this off?
>

Your specification is not exactly clear about how to handle all of the
different cases or what you really want but how about:

>>> 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'}


Oscar

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Dict comp help Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 21:11 +0000

csiph-web