Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29611
| References | <63673.77.105.185.196.1348181901.squirrel@lavabit.com> |
|---|---|
| Date | 2012-09-21 01:33 -0700 |
| Subject | Re: Functional way to compare things inside a list |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.995.1348216421.27098.python-list@python.org> (permalink) |
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
Re: Functional way to compare things inside a list Chris Rebert <clp2@rebertia.com> - 2012-09-21 01:33 -0700
csiph-web