Worthwhile to reverse a dictionary
Erik Max Francis
max at alcyone.com
Wed Dec 14 14:24:18 EST 2005
rudysanford at hotmail.com wrote:
> What is the difference between
>
> " d1 = {'A' : '1', 'B' : '2', 'C' : '3'} "
>
> and
>
> " d1 = dict(A = 1, B = 2, C = 3) " ?
>
> All of the dictionary examples I saw (python.org, aspn.activestate.com,
> Learning Python by Lutz, among others) use d={'x' : 'y'}.
In the latter case the values are ints, whereas in the former they are
strings. But you probably didn't mean that; indeed it is the case that
d1 = {'A': 1, 'B': 2, 'C': 3}
and
d2 = dict(A=1, B=2, C=3)
are equivalent.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
I do not promise to consider race or religion in my appointments. I
promise only that I will not consider them. -- John F. Kennedy
More information about the Python-list
mailing list