Consider the following dictionary:
States= {‘D’: ‘Delhi’, ‘K’: ‘Kerala’, ‘T’: ‘Tamil Nadu’, ‘B’: ‘Bihar’}
Write Python statements for the following:
a) Create the above dictionary.
b) To insert (‘K’: ‘Kanpur’) in the dictionary states.
c) To return the value corresponding to the key ‘T’
d) To return the length of the dictionary states.
e) To delete the dictionary states
Answers
Answered by
2
state_keys, state_vals = ["D", "K", "T", "B"], ["Delhi", "Kerala", "Tamil Nadu", "Bihar"]
States = dict(zip(state_keys, state_vals))
States["K"] = "Kanpur"
print(States["T"])
print(f"States len: {len(States)}")
del States
Answered by
1
Answer:
state_keys, state_vals = ["D", "K", "T", "B"], ["Delhi", "Kerala", "Tamil Nadu", "Bihar"]
States = dict(zip(state_keys, state_vals))
States["K"] = "Kanpur"
print(States["T"])
print(f"States len: {len(States)}")
del States
Similar questions
Chemistry,
2 months ago
Math,
2 months ago
Math,
5 months ago
India Languages,
5 months ago
English,
11 months ago