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


Groups > comp.lang.python > #29604

Functional way to compare things inside a list

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <thorsopia@lavabit.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.204
X-Spam-Level **
X-Spam-Evidence '*H*': 0.61; '*S*': 0.02; 'value.': 0.15; 'subject:compare': 0.16; 'header:User-Agent:1': 0.26; '(e.g.': 0.27; 'subject:list': 0.28; 'dictionary': 0.29; 'to:addr:python- list': 0.33; 'hi,': 0.33; 'list': 0.35; 'functional': 0.36; 'possible': 0.37; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'from:no real name:2**0': 0.60; "'3'": 0.84; 'received:72.249': 0.84
DomainKey-Signature a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=lavabit.com; b=MG1Tk2pYz4guXpDfpomfjvrfiJCGjeqeBMy+w0KRwnLpujFzUczSOFmnrfs9KuSkdTmVWadI1eRvF1IHMXL4ZyBxSZzO9TlGSXywEeY46J4aA9b1/lWGAJNSbaGbpntgXwFWQEvp6imMdN9NrIL5zVqwkXcVr2EOmO7vQWSZJBQ=; h=Message-ID:Date:Subject:From:To:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding;
Date Thu, 20 Sep 2012 18:58:21 -0400 (EDT)
Subject Functional way to compare things inside a list
From thorsopia@lavabit.com
To python-list@python.org
User-Agent SquirrelMail/1.4.13
MIME-Version 1.0
Content-Type text/plain;charset=iso-8859-1
Content-Transfer-Encoding 8bit
X-Mailman-Approved-At Fri, 21 Sep 2012 09:46:44 +0200
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.990.1348213606.27098.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348213606 news.xs4all.nl 6964 [2001:888:2000:d::a6]:41208
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29604

Show key headers only | View raw


Hi,

list = [{'1': []}, {'2': []}, {'3': ['4', '5']}]

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

some_magic(list, '4')
=> '3'

What's the functional way to do it?
Is it possible to do it with a one-liner?





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


Thread

Functional way to compare things inside a list thorsopia@lavabit.com - 2012-09-20 18:58 -0400
  Re: Functional way to compare things inside a list "Ivan@work" <ivan.cvetkovic@pakel.hr> - 2012-09-21 10:24 +0200
  Re: Functional way to compare things inside a list Alexander Blinne <news@blinne.net> - 2012-09-21 10:31 +0200
  Re: Functional way to compare things inside a list Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-09-21 10:52 +0200
    Re: Functional way to compare things inside a list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 12:54 -0700
      Re: Functional way to compare things inside a list Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-21 14:49 -0600
        Re: Functional way to compare things inside a list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 14:45 -0700
        Re: Functional way to compare things inside a list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 14:45 -0700
        Re: Functional way to compare things inside a list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-22 01:25 +0000
          Re: Functional way to compare things inside a list Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-22 00:22 -0600
            Re: Functional way to compare things inside a list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 23:50 -0700
            Re: Functional way to compare things inside a list 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 23:50 -0700
          Re: Functional way to compare things inside a list Jamie Paul Griffin <jamie@kode5.net> - 2012-09-22 08:08 +0100
          Re: Functional way to compare things inside a list Andrew Berg <bahamutzero8825@gmail.com> - 2012-09-22 02:19 -0500
            Re: Functional way to compare things inside a list Ramchandra Apte <maniandram01@gmail.com> - 2012-09-22 21:09 -0700
            Re: Functional way to compare things inside a list Ramchandra Apte <maniandram01@gmail.com> - 2012-09-22 21:09 -0700

csiph-web