I want to sort the sample_list with last digit of the tuples in the list in increasing order.
I want to do that without using sorted. But here even if I am returning list with tuples it is printing None. If I print inside the function instead of returning the variable it will print expected result else it will print None.
Why it is printing None even if I am returning list of tuples?
sample_List = [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)] # Expected Result = [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] def sort_list2(smp_list, new_list=): list_of_last_elements_of_tuples = [x for x in smp_list] if smp_list == : return_tup = new_list return return_tup for element in smp_list: if element == min(list_of_last_elements_of_tuples): new_list.append(element) smp_list.remove(element) sort_list2(smp_list, new_list) op = sort_list2(sample_List) print(op)
Source: Python Questions