Practice makes perfect 14/15

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/removeduplicates?action=lesson_resume

I am asked to get a list of non-repetitive numbers. Below is my code and the error is TypeError: ‘int’ object is not iterable on line 7. I don’t get it. Please help.

def remove_duplicates(a):
  if a == []:
    print([])
  else:  
    b = [a[0]]  # build a 'b' list which has the first number in 'a' list
    a = a.pop(0)  # delete the first number in 'a' list
    for num in a:  # iterates from the second number in the input list
      if num not in b:
        b.append(num)
    return b

here:

a = a.pop(0)  # delete the first number in 'a' list

pop() returns the removed item, so now a is the first item of the list (which is an integer), so then here:

for num in a:

you get an error message that integers are not iterable

4 Likes