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


Groups > comp.lang.python > #29611

Re: Functional way to compare things inside a list

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.030
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'received:mail- vb0-f46.google.com': 0.09; 'sep': 0.09; 'cc:addr:python-list': 0.10; "wouldn't": 0.11; 'value.': 0.15; 'dictionaries': 0.16; 'subject:compare': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'received:209.85.212.46': 0.18; '(or': 0.18; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'subject:list': 0.28; 'chris': 0.28; 'dictionary': 0.29; 'probably': 0.29; 'implement': 0.32; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'functional': 0.36; 'possible': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'more': 0.63; '20,': 0.65; 'guaranteed': 0.76; "'3'": 0.84; 'sender:addr:chris': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=LQaFrC0kri0vN6kugZYWrPsJ52TVw6JDFTPvGsSYLao=; b=GVK1nFtISt/TSH7d1aet6Sj6THtAc57AVa6rQbYQLxFze/TDU/p1arNb2WXgIuS/OD XpVsumf6MMOZvh+f2qzW1CGETawBO9w+b+OH11YkrJXdfmsiDFUt2LBh/B1HiWR19xcc ZmNVEBg4XnFv4UejZFWklHS3UZV1BEhTs9PHg=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=LQaFrC0kri0vN6kugZYWrPsJ52TVw6JDFTPvGsSYLao=; b=FXA9IfSbvhy4drX7B5U469PqnnjguHa0DXTtG5bsO9IHdTTOOo0Cv2ahIqdU6RpffZ jaR+BFx5MFT91zoVg/aXLkbBHRPJJabFqJLc4fLu3F4bqLqXYFZH7CpEQgkaQ7bd4Wz+ lnEmiV26xgeilbPMTJs8uk1rT9x2dccXmskG+O2tlwQkFCxkKwlbzE/EYPpm+QaaXlSO 3asUwbOHMkLjEAcmwfqKW5sI0+VDbyGdbK8ImIu7/a3Cazr9kPl8LSWYui9stmKLUVbM rV8iuJFgiaMh2JTw9mm9uqIbw/0EhHXHpd9k4duLMROqRXo8YFr/IZ989RDC1RYEqEIB VHZQ==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <63673.77.105.185.196.1348181901.squirrel@lavabit.com>
References <63673.77.105.185.196.1348181901.squirrel@lavabit.com>
Date Fri, 21 Sep 2012 01:33:38 -0700
X-Google-Sender-Auth FQnfhA7Ua75yqZ0OBAxCvp8S-uE
Subject Re: Functional way to compare things inside a list
From Chris Rebert <clp2@rebertia.com>
To thorsopia@lavabit.com
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQnPxosIT6tHwKcCP6zujkotjLyOnIr779nf3WTeHYYibQQ2JySVE3e7DNxb6Ws9gt8oxwBe
Cc 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.995.1348216421.27098.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348216421 news.xs4all.nl 6883 [2001:888:2000:d::a6]:56395
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29611

Show key headers only | View raw


On Thu, Sep 20, 2012 at 3:58 PM,  <thorsopia@lavabit.com> wrote:
> Hi,
>
> list = [{'1': []}, {'2': []}, {'3': ['4', '5']}]

Are the dictionaries each guaranteed to only contain a single
key-value pair? (Or is your example just simplistic?)

> I want to check for a value (e.g. '4'), and get the key of the dictionary
> that contains that value.

And what if there is no such dictionary? Or what if there are multiple
such dictionaries?

> (Yep, this is bizarre.)
>
> some_magic(list, '4')
> => '3'
>
> What's the functional way to do it?

Why do you care about the paradigm used?

> Is it possible to do it with a one-liner?

Who cares? It's possible to implement more complicated things in one
line of APL, but most people probably wouldn't recommend it.

Regards,
Chris R.

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


Thread

Re: Functional way to compare things inside a list Chris Rebert <clp2@rebertia.com> - 2012-09-21 01:33 -0700

csiph-web