0
def rm_duplicates_loop(list_name):
new_list = []

#new_list=[num for num in list_name if num not in new_list]

for num in list_name:
    if num not in new_list:
        new_list.append(num)
return new_list

In the function rm_duplicates_loop(list_name) why does the new list list comprehension method is not showing the same exact output as the for loop?

As far as I know, theoretically it should be the same thing in different method resulting the same thing.

  • `return [num for num in list_name if num not in ???]` — Now what? `Not in` what? You can't access the list being constructed while it is being constructed. – deceze Oct 23 '20 at 12:18
  • `new_list` is still empty, while the list comprehension is running/constructs the list. – Maurice Meyer Oct 23 '20 at 12:18
  • Wouldn't it pick up the common items from another list which had duplicate items. I mean the new list would have all the items the previous list had removing all the duplicates – Biting Panda Oct 23 '20 at 12:47

0 Answers0