0
Can anyone explain? Dict(((1,2),))
Why it's working when I remove , after a tuple it doesn't work then what's the logic.?
1 Answer
+ 2
because putting the comma (,) after the tuple make the parenthesis around it another tuple (iterable), while without, parenthesis are just math parenthesis ^^
dict expect an iterable of (key, value) tuple as initialization data...
if you don't put the comma, then it's equivalent to write: dict((1,2)) wich is a tuple of int (not tuple of tuple)...
however, if you have more than one value in the tuple, the last comma is not required:
dict(((1,2),(3,4)))
works well ;)