Re: A little morning puzzle

Discussion in 'Python' started by Dwight Hutto, Sep 19, 2012.

  1. Dwight Hutto

    Dwight Hutto Guest

    > I have a list of dictionaries. They all have the same keys. I want to find the
    > set of keys where all the dictionaries have the same values. Suggestions?


    Here is my solution:


    a = {}
    a['dict'] = 1

    b = {}
    b['dict'] = 2

    c = {}
    c['dict'] = 1

    d = {}
    d['dict'] = 3

    e = {}
    e['dict'] = 1


    x = [a,b,c,d,e]
    collection_count = 0

    for dict_key_search in x:
    if dict_key_search['dict'] == 1:
    collection_count += 1
    print dict_key_search['dict']


    Might be better ones though.


    --
    Best Regards,
    David Hutto
    CEO: http://www.hitwebdevelopment.com
    Dwight Hutto, Sep 19, 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. Neal Becker

    A little morning puzzle

    Neal Becker, Sep 19, 2012, in forum: Python
    Replies:
    2
    Views:
    162
    Paul Rubin
    Sep 19, 2012
  2. Peter Otten

    Re: A little morning puzzle

    Peter Otten, Sep 19, 2012, in forum: Python
    Replies:
    0
    Views:
    159
    Peter Otten
    Sep 19, 2012
  3. Peter Otten

    Re: A little morning puzzle

    Peter Otten, Sep 19, 2012, in forum: Python
    Replies:
    9
    Views:
    148
    Prasad, Ramit
    Sep 27, 2012
  4. Antoon Pardon

    Re: A little morning puzzle

    Antoon Pardon, Sep 19, 2012, in forum: Python
    Replies:
    0
    Views:
    148
    Antoon Pardon
    Sep 19, 2012
  5. Dwight Hutto

    Re: A little morning puzzle

    Dwight Hutto, Sep 19, 2012, in forum: Python
    Replies:
    0
    Views:
    138
    Dwight Hutto
    Sep 19, 2012
Loading...

Share This Page