Question discussion

What is the output of the following Python code?d = {c: i for i, c in enumerate("hello")} print(len(d), d["l"])

1381Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

d = {c: i for i, c in enumerate("hello")}
print(len(d), d["l"])
  • A4 3
  • B5 2
  • C4 2
  • D5 3
Correct answer: A

Explanation

The duplicate key 'l' is overwritten by its last index (3), leaving 4 distinct keys.

Discussion 0

Nobody has replied yet. Start the discussion!