Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
Peter Otten wrote: > Paul Rubin wrote: > >> Peter Otten <__pete...@web.de> writes: >>> assert len(keydict) == len(mydict) >> >> assert set(keydict) == set(mydict) > > The weaker check is O(1), and, combined with the succeeding for loop, > implies the above. Sorry, I have to take that back: Py

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
Paul Rubin wrote: > Peter Otten <__pete...@web.de> writes: >> assert len(keydict) == len(mydict) > > assert set(keydict) == set(mydict) The weaker check is O(1), and, combined with the succeeding for loop, implies the above. -- https://mail.python.org/mailman/listinfo/python-list

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Paul Rubin
Peter Otten <__pete...@web.de> writes: > assert len(keydict) == len(mydict) assert set(keydict) == set(mydict) -- https://mail.python.org/mailman/listinfo/python-list

Re: Converting the keys of a dictionary from numeric to string

2016-10-20 Thread Peter Otten
pozz wrote: > I have a dictionary where the keys are numbers: > > mydict = { 1: 1000, 2: 1500, 3: 100 } > > I would like to convert keys from number to string representation: > > mydict = { "apples": 1000, "nuts": 1500, "tables": 100 } > > Of course, somewhere I have the association between ke

Re: Converting the keys of a dictionary from numeric to string

2016-10-19 Thread Paul Rubin
pozz 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, 'nut

Converting the keys of a dictionary from numeric to string

2016-10-19 Thread pozz
I have a dictionary where the keys are numbers: mydict = { 1: 1000, 2: 1500, 3: 100 } I would like to convert keys from number to string representation: mydict = { "apples": 1000, "nuts": 1500, "tables": 100 } Of course, somewhere I have the association between key-numbers and key-strings, ma