Menu

(Solved) : Write Python Function Given Dictionary Returns List Key Value Pairs Sorted Value Example I Q44042463 . . .

Write a python function which given a dictionary, returns a list of key-value pairs sorted by value. For example, if the inpu

code.py New 1 from typing import Dict, List, Tuple OVOU AWN 3. def sorted_dict(to_sort : Dict[str, int]) -> List[Tuple[str, i

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 | Show transcribed image text 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 |

Expert Answer


Answer to Write a python function which given a dictionary, returns a list of key-value pairs sorted by value. For example, if the…

OR