Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a duplicate in a list without using set in python?

Tags:

python

I know that we can use the set in python to find if there is any duplicate in a list. I was just wondering, if we can find a duplicate in a list without using set.

Say, my list is

a=['1545','1254','1545']

then how to find a duplicate?


1 Answers

>>> lis = []
>>> a=['1545','1254','1545']
>>> for i in a:
...     if i not in lis:
...         lis.append(i)
... 
>>> lis
['1545', '1254']
>>> set(a)
set(['1254', '1545'])
like image 186
Tanveer Alam Avatar answered Dec 08 '25 16:12

Tanveer Alam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!