Change the format of an unhashable dictionary

Discussion in 'Python' started by Dorsa, Jan 21, 2011.

  1. Dorsa

    Dorsa

    Joined:
    Jan 21, 2011
    Messages:
    2
    Hi everyone.
    I have a dictionary in dictionary created using dict() that looks like this:

    Code:
    Mobile {'Nokia': 15, 'Motorola': 6, 'HTC': 10}
    Car {'red': 5, 'gray': 7, 'black': 13, 'white': 2}
    Camera {'Canon':7, 'Sony': 5}
    .
    .
    
    There are thousands of item groups like these in the dictionary. I want to change the structure from a dictionary to a 3-column structure like this:
    Code:
    Mobile Nokia 15 
              Motorola 6
              HTC 10
    
    This is how I am trying to format it:
    Code:
    for key in gitems.keys():
        print key
        for item in gitems.values():
            print("\t\t{item:11}{number:11}".format(item=item, number=gitems[number]))
    But it gives the error message "TypeError: unhashable type: 'dict'", for obvious reasons. Since I am a newbie, I don't know how to go about the problem. So is there any other way I could do this? Thanks.
     
    Dorsa, Jan 21, 2011
    #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. Ilias Lazaridis
    Replies:
    6
    Views:
    446
    Ilias Lazaridis
    Feb 21, 2006
  2. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    Using Dictionaries in Sets - dict objects are unhashable?

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Mar 22, 2006, in forum: Python
    Replies:
    3
    Views:
    19,497
    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
    Mar 22, 2006
  3. james_027
    Replies:
    1
    Views:
    330
    Marc 'BlackJack' Rintsch
    Aug 22, 2007
  4. Dorsa
    Replies:
    0
    Views:
    187
    Dorsa
    Jan 21, 2011
  5. Olive

    Making unhashable object

    Olive, Feb 19, 2013, in forum: Python
    Replies:
    2
    Views:
    128
    Peter Otten
    Feb 19, 2013
Loading...

Share This Page