The program creates a dictionary with keys taken from a list of strings and values taken from a dictionary.
stu = ["Siva", "Sam", "Ram", "Pooja"] defaults = {"designation": "Student", "Department": "BCA"} result = dict.fromkeys(stu, defaults) print(result) # Individual data print("\nSiva :",result["Siva"]) print("\nSam :",result["Sam"]) print("\nRam :",result["Ram"]) print("\nPooja :",result["Pooja"])
{'Siva': {'designation': 'Student', 'Department': 'BCA'}, 'Sam': {'designation': 'Student', 'Department': 'BCA'}, 'Ram': {'designation': 'Student', 'Department': 'BCA'}, 'Pooja': {'designation': 'Student', 'Department': 'BCA'}} Siva : {'designation': 'Student', 'Department': 'BCA'} Sam : {'designation': 'Student', 'Department': 'BCA'} Ram : {'designation': 'Student', 'Department': 'BCA'} Pooja : {'designation': 'Student', 'Department': 'BCA'}
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions