I need to write a merge_sort
and a corresponding merge_two_halves
function which sorts the parameter list of tuples. The list should be sorted in reverse order (biggest-smallest). Each tuple in the list of tuples which is passed as a parameter to the merge_sort
function contains two elements and the merge_sort
function should use the first element (a string) of each tuple as the sort key.
such that:
def main():
print("1.")
a_list = [0, 0, 0, 0, 0]
list_of_tuples_left = [('Tim', 194493), ('Song', 201670), ('Abe', 203126)]
list_of_tuples_right = [('Jim', 194169), ('Ben', 179619)]
merge_two_halves(a_list, list_of_tuples_left, list_of_tuples_right)
print(a_list)
print()
print("2.")
a_list = [0, 0, 0, 0, 0, 0, 0, 0]
list_of_tuples_left = [('Joseph', 194493), ('Ethan', 201670), ('Christopher',
203126),('Andrew', 202301)]
list_of_tuples_right = [('William', 194169), ('David', 179619), ('Anthony',
191681), ('Alexander', 178646)]
merge_two_halves(a_list, list_of_tuples_left, list_of_tuples_right)
print(a_list)
print()
print("3.")
names_id_tuples = get_list_of_tuples_from_file("namesId.txt")
merge_sort(names_id_tuples)
for i in range(30):
print(names_id_tuples[i])
print()
I don't even know where to begin with this. Any help would be awesome