Q. The following code is giving some error. Find out the error and correct it.
d1 = {"a" : 1, 1 : "a", [1, "a"] : "two"}
Answer =
There should not list as key. If we use tuple in place of list as a key then, it give no error.
Like this: -
d1 = {"a" : 1, 1 : "a", (1, "a") : "two"}
What is the difference in here then?
ReplyDeletelist is mutable data type and tuple is immutable data type.
DeleteWhy we are giving their 1st bracket???
ReplyDeletefor tuples and we are having 2 values in one key. :)
Deletefor tuples and we are having 2 values in one key. :)
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )