Delete multiple same elements from Python List

Rafsan Jany
Sep 3, 2018 · 1 min read

Let we have a list contains different elements. Among these elements, some elements repeat several times, for instance we have three 1s and two 3s in our list like
l1 = [1, 2, 3, 4, 1, 1, 5, 6, 3, 7]

We will delete the elements that occurs multiple times. Let’s do it:

l1 = [1, 2, 3, 4, 1, 1, 5, 6, 3, 7]

l2 = [] #empty list
l3 = [] # empty list

for i in l1:
….if i not in l2:
……..l2.append(i)
….else:
……..l3.append(i)

for j in l2[:]:
….if j in l3:
……..l2.remove(i)

print l2

Output: [2, 3, 4, 5, 6, 7]

multiple same elements delete from list
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade