Python - Group first elements by second elements in Tuple list
Given List of tuples, group 1st elements on basis of 2nd elements. Input : test_list = [(6, 5), (2, 7), (2, 5), (8, 7), (3, 7)] Output : {5: [6, 2], 7: [2, 8, 3]} Explanation : 5 occurs along with 6 and 2 in tuple list, hence grouping. Input : test_list = [(6, 5), (2, 7), (2, 5), (8, 7)] Output : {5