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"}

5 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. What is the difference in here then?

    ReplyDelete
    Replies
    1. list is mutable data type and tuple is immutable data type.

      Delete
  2. Why we are giving their 1st bracket???

    ReplyDelete
    Replies
    1. for tuples and we are having 2 values in one key. :)

      Delete
  3. for tuples and we are having 2 values in one key. :)

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post