Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Change the format of an unhashable dictionary

Reply
Thread Tools

Change the format of an unhashable dictionary

 
 
Dorsa Dorsa is offline
Junior Member
Join Date: Jan 2011
Posts: 2
 
      01-21-2011
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making unhashable object Olive Python 2 02-19-2013 01:54 PM
Change the format of an unhashable dictionary Dorsa Python 0 01-21-2011 02:58 PM
creating a dictionary from a dictionary with regex james_027 Python 1 08-22-2007 07:39 AM
Using Dictionaries in Sets - dict objects are unhashable? =?ISO-8859-1?Q?Gregory_Pi=F1ero?= Python 3 03-22-2006 02:16 PM
[DICTIONARY] - Copy dictionary entries to attributes Ilias Lazaridis Python 6 02-21-2006 11:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57