leo_bouts
leo_bouts

Reputation: 337

Appending two or more zeros in a python dictionary

I want to add two zeros on a dictionary as values. When i do this the python dictionary returns only a single zero. I don't want to use a list. Why the dictionary behaves like this?

dictionary = {}

#new key and values

dictionary['a'] = {0.0,0.0}

#expected result {'a': {0.0,0.0}}

print(dictionary)

the console returns this as an output.

{'a': {0.0}}

Upvotes: 0

Views: 69

Answers (1)

Kent Shikama
Kent Shikama

Reputation: 4060

If you don't want to use lists, you can use a tuple, which unlike sets allows duplicates.

In [1]: dictionary = {}                                                         

In [2]:  
   ...: dictionary['a'] = (0.0,0.0)                                             

In [3]:  
   ...: print(dictionary)                                                       
{'a': (0.0, 0.0)}

Upvotes: 2

Related Questions