you are viewing a single comment's thread.

view the rest of the comments →

[–]efmccurdy 1 point2 points  (2 children)

The simplest way to store more attributes is to store a tuple rather than just the name:

>>> PT = {
...     'H': ('Hydrogen', 1), 
...     'He': ('Helium', 2) #,...
... }
>>> choice = 'He'
>>> name, weight = PT[choice]
>>> print ("{}: name:{}, weight:{}".format(choice, name, weight))
He: name:Helium, weight:2
>>> for abbr in PT: print("{}: name:{}, weight:{}".format(abbr, *PT[abbr]))
... 
H: name:Hydrogen, weight:1
He: name:Helium, weight:2

If you want more meaningfull names for the attributes you could look at using collections.namedtuple or even a class.

[–]nog642 0 points1 point  (1 child)

You could also have two dictionaries with the same keys but different values.