This program takes a list of tuples, sorts it according to a specific order, and returns a new list of tuples with the sorted elements. Here's what happens step-by-step:
So the program takes a list of tuples, creates a dictionary from it, and returns a new list of tuples sorted according to the order specified in ord_list.
val = [('B', 68), ('D', 70), ('A', 67), ('C', 69)] print("Original List : ", val) ord_list = ['A', 'B', 'C', 'D'] temp = dict(val) res = [(key, temp[key]) for key in ord_list] print("The Ordered Tuple List : " , res)
Original List : [('B', 68), ('D', 70), ('A', 67), ('C', 69)] The Ordered Tuple List : [('A', 67), ('B', 68), ('C', 69), ('D', 70)]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions