Write a Python program to create a dictionary from two lists without losing duplicate values. If there is more values in the key list, then provided key should return an empty set if there is no match. (Hint: use defaultdict) Example:
class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX']
id_list = [1, 2, 2, 3]
Output: assuming you store the values in a data structure named temp
print(temp["Class-V"]) # {1}
print(temp["Class-IX"]) # set()
can you please try and do on google colab
class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX'] id_list = [1, 2, 2, 3] temp = {} for i in range(len(class_list)): if i<len(id_list): temp[class_list[i]] = id_list[i] else: temp[class_list[i]] = set() print(temp["Class-V"]) # {1} print(temp["Class-IX"]) # set()
Get Answers For Free
Most questions answered within 1 hours.