Question: Write a python function which given a dictionary, returns a list of key-value pairs sorted by value. For example, if the input is: '{a :


Write a python function which given a dictionary, returns a list of key-value pairs sorted by value. For example, if the input is: '{"a" : 4, "b" : 3, "C": 2, "d" : 1} The output should be: [('d', 1), ('c', 2), ('b', 3), ('a',4)] Note: To receive full credit on this problem sorted must be called with the key argument provided. code.py New 1 from typing import Dict, List, Tuple OVOU AWN 3. def sorted_dict(to_sort : Dict[str, int]) -> List[Tuple[str, int]]: lista = [] for key, val in sorted(to_sort.items(), key = val): tup = (key, val) lista.append(tup) return lista 9 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
