write two difference between list and dictionary with one example of each
Answers
Answer:
List Dictionary
1. Lists are mutable in nature 1. Dictionaries are mutable, but
keys do not allow duplicates
2. Collection of various 2. Collection of elements in the elements just like an array hashed structure as key-value in C++. pairs.
For Example: For Example:
slist = ["Python", "is", "Fun"] sdict = { "vegetable": "potato",
print(slist) "fruit": "banana",
"chocolate": "gems"}
print(sdict)
Output Output
['Python', 'is', 'Fun'] {'vegetable': 'potato', 'fruit':
'banana', 'chocolate': 'gems'}