I want to group students into two different lists according to the subjects but the function is failing to create different lists. I am aware that the instance of the list created in both cases is the same but I am unable to find a workable solution to the same.
def add_tolist(name, students=[]):
students.append(name)
return students
idc306 = add_tolist('ram')
idc101 = add_tolist('shyam')
idc101 = add_tolist('deepa',idc101)
print idc101, idc306
The results should be : ['shyam', 'deepa'] ['ram']
But its printing : ['ram', 'shyam', 'deepa'] ['ram', 'shyam', 'deepa']