Answers for "checking for duplicates in python"

3

python has duplicates

def has_duplicates(lst):
    return len(lst) != len(set(lst))
    
x = [1,2,3,4,5,5]
has_duplicates(x) 			# True
Posted by: Guest on February-16-2021
8

count the duplicates in a list in python

some_list=['a','b','c','b','d','m','n','n']

 my_list=sorted(some_list)
 
duplicates=[]
for i in my_list:
     if my_list.count(i)>1:
         if i not in duplicates:
             duplicates.append(i)
 
print(duplicates)
Posted by: Guest on January-30-2021
1

duplicate in list python

a = [1,2,3,2,1,5,6,5,5,5]

import collections
print([item for item, count in collections.Counter(a).items() if count > 1])

## [1, 2, 5]
Posted by: Guest on May-21-2020
0

python find duplicates in string

from collections import Counter

def do_find_duplicates(x):
    x =input("Enter a word = ")
    for key,val in Counter(x).items():
        print(key,val)
Posted by: Guest on April-17-2021
1

python check for duplicate

def checkDuplicate(user):
    if len(set(user)) < len(user):
        return True
    return False
Posted by: Guest on November-20-2020

Code answers related to "checking for duplicates in python"

Python Answers by Framework

Browse Popular Code Answers by Language