Leyla Tulu
Leyla Tulu

Reputation: 3

Find the repetitive word in the list and remove the word from the list

I'm getting input information from the user. There are repeated entries. When I find these repeated words, I have to remove this word from the list.

For example, our inputs are: "a, b, c, b, e, a".

I need to get the output to be "c, e".

What function should I write for this?

def essizkelime():
    import pandas as pd 
    a = int(input("Kaç kelime gireceksiniz?")) 
    i = 1
    l = []
    while i <= a:
        if i == 1:              
            b = input(print("Kelimeleri giriniz:","\n"))
            l.append(b)
        else:
            b = input()
            l.append(b)
        #print(str(i) + ". Kelimeniz:" + str(b),"\n")
        i += 1
    
    tekliler = set(l)
    print(tekliler) 
    print("Eşsiz Kelimeler: " + str(tekliler))    
    
essizkelime()

Upvotes: 0

Views: 39

Answers (1)

Jonas Bystr&#246;m
Jonas Bystr&#246;m

Reputation: 26139

l = 'a, b, c, b, e, a'.split(', ')
from collections import Counter
print([l for l,c in Counter(l).items() if c==1])

outputs

['c', 'e']

Upvotes: 1

Related Questions