I am trying to create a list of dictionary. The expected output is that for 5 Students, it should have 5 dictionary items in the list with keys being Name and Marks (in a list). The output that I get is having the information repeated 5 times for the last student in iteration. Please let me know where am I making an error.
import random
name_list=[]
name_list = ['A','B','C','D','E']
stud_dict=dict()
stud_dict_list = []
for name in name_list:
mark_list = []
for i in range(1,11):
mark_list.append(random.randint(0,100))
stud_dict['Name']=name
stud_dict['Marks']=mark_list
stud_dict_list.append(stud_dict)
print(stud_dict_list)
output:
[{'Name': 'E', 'Marks': [91, 71, 93, 33, 52, 90, 97, 98, 41, 18]}, {'Name': 'E', 'Marks': [91, 71, 93, 33, 52, 90, 97, 98, 41, 18]}, {'Name': 'E', 'Marks': [91, 71, 93, 33, 52, 90, 97, 98, 41, 18]}, {'Name': 'E', 'Marks': [91, 71, 93, 33, 52, 90, 97, 98, 41, 18]}, {'Name': 'E', 'Marks': [91, 71, 93, 33, 52, 90, 97, 98, 41, 18]}]