0
list=['A', 'R', 'I','J','I','T','T']

def reccuring():
    count=0
    list1=[]
    for i in list:
        if list.count(i)>1:
            list1.append(i)
    return list1
reccuring()

OutPut

['I', 'I', 'T', 'T']

I am getting the recurring elements as many times as present in the list. What modification do I have to do to get the recurring elements only once?

Thank You

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

0

Better name your variables and use a set

values = ['A', 'R', 'I', 'J', 'I', 'T', 'T']

def reccuring():
    count = 0
    result = set()
    for value in values:
        if value not in result and values.count(value) > 1:
            result.add(value)
    return result

reccuring()
azro
  • 53,056
  • 7
  • 34
  • 70