3

I have the following code snippet:

mirna2age = {}
for i in agesdb:
    mirna2age.setdefault(i[0],default=[]).append(i[1])

However, Python returns

TypeError: setdefault() takes no keyword arguments

I am unsure why. Does anyone have any ideas?

indiaash524
  • 167
  • 1
  • 9

2 Answers2

7

Set default should be used like:

mydict.setdefault(key, defaultvalue)

Don't use kwargs, just provide teh default as the second argument.

jaime
  • 2,234
  • 1
  • 19
  • 22
2

The arguments are positional so change the call to:

    mirna2age.setdefault(i[0], []).append(i[1])

the message is telling you this function doesn't define named arguments

gkusner
  • 1,244
  • 1
  • 11
  • 14