Why the below code in where I am using list comprehension doesn't work, but the common way does it?
exams = [1,2,3,1,2,3,4,1,5,1]
repeatedExams = []
# EXCPECTED OUPUT
# repeatedExams = [1,2,3]
# IF I USE repeatedExams.append(i)
repeatedExams = [repeatedExams.append(i) for i in exams if (exams.count(i)>1) and (i not in repeatedExams)]
# OUTPUT
# repeatedExams = [None,None,None]
# IF I ONLY USE i
repeatedExams = [i for i in exams if (exams.count(i)>1) and (i not in repeatedExams)]
# OUTPUT
# repeatedExams = [1,2,3,1,2,3,4,1,5,1]
# WORK
for i in exams:
if exams.count(i) > 1 and i not in repeatedExams:
repeatedExams.append(i)
# OUTPUT
# repeatedExams = [1,2,3]