How to remove duplicates from a list in Python

2 Answers

0 votes
lst = ["python", "php", "python", "php", "c", "c++", "java", "java"]

lst = list(dict.fromkeys(lst))

print(lst)



'''
run:
 
['c', 'java', 'c++', 'php', 'python']
 
'''

 



answered Jan 9, 2019 by avibootz
0 votes
lst = ["python", "php", "python", "php", "c", "c++", "java", "java"]

lst = list(set(lst))
 
print(lst)
 
  
 
'''
run:
 
['php', 'c', 'c++', 'java', 'python']
 
'''

 



answered Jan 27, 2020 by avibootz
...