Re: Functional way to compare things inside a list

Discussion in 'Python' started by Chris Rebert, Sep 21, 2012.

  1. Chris Rebert

    Chris Rebert Guest

    On Thu, Sep 20, 2012 at 3:58 PM, <> 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.
     
    Chris Rebert, Sep 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gf gf
    Replies:
    6
    Views:
    323
    Dave Benjamin
    Mar 5, 2005
  2. Replies:
    15
    Views:
    272
    Ramchandra Apte
    Sep 23, 2012
  3. Chris Angelico
    Replies:
    0
    Views:
    208
    Chris Angelico
    Sep 21, 2012
  4. Chris Rebert
    Replies:
    0
    Views:
    176
    Chris Rebert
    Sep 21, 2012
  5. Chris Angelico
    Replies:
    0
    Views:
    182
    Chris Angelico
    Sep 21, 2012
Loading...

Share This Page