Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started