0

Basically I have a dictionary that uses a tuple as a key. I want to utilize the get() function so that I can assign a default value if the key does not exist in the dictionary. However, I get a TypeError: get() takes no keyword arguments error when I attempt to do this. Here is my code that raises an exception:

dict = {('a', 'b'): 10}
dict.get(('a', 'b'), default = 0)

How can I accomplish what I am trying to do?

Anonymous
  • 93
  • 8

1 Answers1

2

Use:

dict.get(('a', 'b'), 0)

The second parameter has no keyword (see python documentation on standard types)

get(key[, default])

Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this

method never raises a KeyError.

mozway
  • 194,879
  • 13
  • 39
  • 75