0

Say I had a list called "list1" list1 = [1,2,3,4,5] and I had another list called "list2" list2 = [1,2,3] What would be the easiest way to take out 1,2,3 without using a loop to iterate through list2 then deleting them from list1? Thanks!

The shape
  • 359
  • 3
  • 10

1 Answers1

2

That's what set() is for.

print(set(list1))

output

[1,2,3]
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44