Menu

gitpiper

has_duplicates python Code Snippet in 2023

listbeginner

Last Updated: 30 January 2023

Checks if there are duplicate values in a flat list.

  • Use set() on the given list to remove duplicates, compare its length with the length of the list.
def has_duplicates(lst): return len(lst) != len(set(lst))
x = [1, 2, 3, 4, 5, 5] y = [1, 2, 3, 4, 5] has_duplicates(x) # True has_duplicates(y) # False

python snippet similar to has_duplicates For You in February 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️