Order Tuples by List

lst = [('for', 3), ('python', 9), ('engineers', 10)]

print("The original list is : " + str(lst))

ord_list = ['python', 'for', 'engineers']

temp = dict(lst)

res = [(key, temp[key]) for key in ord_list]

print("The ordered tuple list : " + str(res))


No comments: