Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Functional way to compare things inside a list (http://www.velocityreviews.com/forums/t952490-re-functional-way-to-compare-things-inside-a-list.html)

Chris Rebert 09-21-2012 08:33 AM

Re: Functional way to compare things inside a list
 
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.


All times are GMT. The time now is 08:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.