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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 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 184 views
2 answers 183 views
2 answers 131 views
1 answer 136 views
3 answers 230 views
1 answer 174 views
...