- Code: Select all
`def has_duplicates(alist):`

alpha=[]

numeric=[]

for i,j in enumerate(alist):

if type(j)!=int and alist.count(j)>1:

if all(j != alpha[x] for x in alpha): # Tried this to eliminate duplicating the alpha list

alpha+=[int(i)]

for i,j in enumerate(alist):

if type(j)==int and alist.count(j)>1:

if all(j != numeric[x] for x in numeric): # Tried this to eliminate duplicating the numeric list

numeric+=[int(i)]

return alpha,numeric

This is not an efficient code.

Another point is given a list [1,2,3,'a','b','b','c',4,4,'A']

- Code: Select all
`has_duplicates([1,2,3,'a','b','b','c',4,4,'A'])`

Out[77]: ([4, 5], [7, 8])

Q1. the problem is 4==5 and 7==8 in the result. I would like to know if something like findall feature exists for lists where

Q2 .How do I get just ([4],[7]) in this particular example??

Q3. How to search for only numbers in a list using some search function available for list??