Answers for "does sets allow 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
0

python set remove duplicate elements

new_menu = ['Hawaiian', 'Margherita', 'Mushroom', 'Prosciutto', 'Meat Feast', 'Hawaiian', 'Bacon', 'Black Olive Special', 'Sausage', 'Sausage']

final_new_menu = list(set(new_menu))

print(final_new_men)

#output = ['Hawaiian', 'Margherita', 'Mushroom', 'Prosciutto', 'Meat Feast', 'Bacon', 'Black Olive Special', 'Sausage']
Posted by: Guest on May-20-2021

Code answers related to "does sets allow duplicates in python"

Python Answers by Framework

Browse Popular Code Answers by Language