You can have a look at it, here is how you can use the sorted method with custom key:
lst = [('hong kong', 'state'),
('hong kong', 'city'),
('hong', 'country'),
('kong', 'city'),
('hong kong', 'country')]
def create_dict(l):
sorted_lst = sorted(l, key=lambda x: len(x[0]))
return {k: v for v, k in sorted_lst}
print(create_dict(lst))
Output:
{'country': 'hong kong', 'city': 'hong kong', 'state': 'hong kong'}
If you are a beginner and want to know more about Python the do check out the python for data science