how to add new tuple as key in dictionary?
John Gordon
gordon at panix.com
Wed Jul 5 12:05:20 EDT 2017
In <344c23f8-f440-4c23-a5e6-9f93b0145e02 at googlegroups.com> Ho Yeung Lee <jobmattcon at gmail.com> writes:
> I find that list can not be key in dictionary
> then find tuple can be as key
> but when I add new tuple as key , got error in python 2.7
> groupkey = {(0,0): []}
> groupkey[tuple([0,3])] = groupkey[tuple([0,3])] + [[0,1]]
The right-hand side of your expression is rightly complaining that
groupkey[(0,3)] doesn't exist.
Would you expect to say
a = a + 1
When a doesn't exist? Your code tries to do much the same thing.
--
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list
mailing list