small medium large xlarge

 

PracProg2setdict

Exercise 1

def find_dups(list): ””” (list) -> set

Return the number of duplicates numbers from a list.
 Use the fact that sets does not accept duplicates.
 Length of a set remains the same when trying the add
 an already existing element.
""" 
 elem_set = set()
 dups_set = set()
 for entry in list:
     len_initial = len(elem_set)
     elem_set.add(entry)
     len_after = len(elem_set)
     if len_initial == len_after:
         dups_set.add(entry)
return(dups_set)
Page History
  • V34: Jennifer Campbell [over 2 years ago]
  • V25: Jennifer Campbell [over 2 years ago]
  • V24: Jennifer Campbell [over 2 years ago]
  • V33: System [over 2 years ago]
  • V32: System [over 2 years ago]
  • V31: System [over 2 years ago]
  • V30: System [over 2 years ago]
  • V29: System [over 2 years ago]
  • V28: System [over 2 years ago]
  • V27: System [over 2 years ago]