Generation

generate functionMon, 26 Dec 2022

There are 2 functions. One looks for duplicate values and makes a dictionary. The second changes the duplicates to the desired value. The first function (find_duplicates) works correctly. But the second function (change_duplicates) is incomplete. Finish the code so that the duplicate student number changes to the one in brackets in the change_duplicates function. def find_duplicates(lst): stnums = [] cnt = {} for el in lst: stnums.append(el[0]) for i in stnums: if i in cnt: cnt[i] += 1 else: cnt[i] = 1 return cnt def change_duplicates(lst, replacing_num): stnums = [] duplicates = find_duplicates(lst) for k, v in duplicates.items(): if v > 1: stnums = [k] for student in lst: if stnums in lst: #need right code#

def find_duplicates(lst): stnums = [] cnt = {} for el in lst: stnums.append(el[0]) for i in stnums: if i in cnt: cnt[i] += 1 else: cnt[i] = 1 return cnt def change_duplicates(lst, replacing_num): stnums = [] duplicates = find_duplicates(lst) for k, v in duplicates.items(): if v > 1: stnums = [k] for student in lst: if stnums in lst: #need right code#

Questions about programming?Chat with your personal AI assistant