Python add-on dictionary, TypeError: unhashable type?

abc = {}
abc[int: anotherint]

Then an error occurred. TypeError: non-writable type? Why did I get this? I tried str ()

+5
source share
3 answers

This seems to be a syntax issue:

>>> abc = {}
>>> abc[1] = 2
>>> abc
{1: 2}
>>> abc = {1:2, 3:4}
>>> abc
{1: 2, 3: 4}
>>> 

At least the syntax of the following is incorrect

abc[int: anotherint]

I think you want to say

abc = [int: anotherint]

This is not true. The right way -

abc = {int: anotherint}

if abcalready defined in this case:

abc[int] = anotherint

is also a valid option.

+7
source

: - , , int (, [. ]) anotherInt. , python, , , .

-, x [{int: anotherInt}]:

, , , , python , - , ... :

x={}
x[x]=1

, , , 1?

x[{}]
x[{x:x}]
x[{{}:x}]
x[x]

, {} != {} ,

+3

Since the title says add, and none of the answers gave a solution to add things to the dictionary, I give it a try:

abc = {}
abc[1]= 2
abc['a'] = [3,9,27]
==> a = {1:2, 'a':[3,9,27]}
0
source

All Articles