Working on CODE CHALLENGE: DICTIONARIES # Largest Value , I googled some keywords and wrote two codes. Both work, but for sake of developing something, how can I calculate how fast is each or how much memory will it take(without counting the lines as it could be impractical for longer codes)
Kindly help. Thank you
def max_key1(my_dictionary): output = [(value, key) for key, value in my_dictionary.items()] print(output) return (max(output))
def max_key(my_dictionary): largest_key = " " largest_value = float(-9999) for k , v in my_dictionary.items(): if largest_value < v : largest_value = v largest_key = k return largest_key
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!