Menu

gitpiper

has_duplicates python Code Snippet in 2024

listbeginner

Last Updated: 23 December 2024

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 December 2024

Subscribe to our Newsletter

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

© 2024 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! ✌️