Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to remove duplicate items from list in Python

4 Answers

0 votes
lst = [34, 78, 34, 90, 'python', 'java', 7.35, 34, 'python']
  
index = 1
while index < len(lst):
    if lst[index] in lst[ : index]:
        lst.pop(index)
    else:
        index += 1

print(lst) 



'''
run:

[34, 78, 90, 'python', 'java', 7.35]

'''

 



answered Jan 10, 2021 by avibootz
0 votes
lst = [34, 78, 34, 90, 'python', 'java', 7.35, 34, 'python']
  
lst = list(set(lst)) 

print(lst) 



'''
run:

[34, 7.35, 'java', 78, 'python', 90]

'''

 



answered Jan 10, 2021 by avibootz
0 votes
lst = [34, 78, 34, 90, 'python', 'java', 7.35, 34, 'python']
  
lst = [i for v, i in enumerate(lst) if i not in lst[:v]] 

print(lst) 



'''
run:

[34, 78, 90, 'python', 'java', 7.35]

'''

 



answered Jan 10, 2021 by avibootz
0 votes
from collections import OrderedDict 

lst = [34, 78, 34, 90, 'python', 'java', 7.35, 34, 'python']
  
lst = list(OrderedDict.fromkeys(lst)) 

print(lst) 



'''
run:

[34, 78, 90, 'python', 'java', 7.35]

'''

 



answered Jan 10, 2021 by avibootz

Related questions

1 answer 268 views
2 answers 291 views
2 answers 230 views
1 answer 230 views
3 answers 362 views
1 answer 269 views
...