Converting the keys of a dictionary from numeric to string
Paul Rubin
no.email at nospam.invalid
Wed Oct 19 21:15:01 EDT 2016
pozz <pozzugno at gmail.com> writes:
> I have a dictionary where the keys are numbers: ...
Python 2.7.5:
>>> mydict = { 1: 1000, 2: 1500, 3: 100 }
>>> keydict = { 1: "apples", 2: "nuts", 3: "tables" }
>>> newdict = dict((keydict[k],v) for k,v in mydict.items())
>>> print newdict
{'tables': 100, 'nuts': 1500, 'apples': 1000}
More information about the Python-list
mailing list