Change the format of an unhashable dictionary

Joined
Jan 21, 2011
Messages
2
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top