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


Groups > comp.lang.python > #29611 > unrolled thread

Re: Functional way to compare things inside a list

Started byChris Rebert <clp2@rebertia.com>
First post2012-09-21 01:33 -0700
Last post2012-09-21 01:33 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#29611 — Re: Functional way to compare things inside a list

FromChris Rebert <clp2@rebertia.com>
Date2012-09-21 01:33 -0700
SubjectRe: Functional way to compare things inside a list
Message-ID<mailman.995.1348216421.27098.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web