Question

Python 3. Define a function called sorted_by_keys that takes a dictionary as input and returns a...

Python 3. Define a function called sorted_by_keys that takes a dictionary as input and returns a list of its values, sorted in alphabetic order based on the keys that have those values

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def sorted_by_keys(d):
    lst = list(sorted(d.items()))
    values = []
    for k, v in lst:
        values.append(v)
    return values


# Testing the function here. ignore/remove the code below if not required
dictionary = {
    "this": 9,
    "is": 2,
    "great": 4
}
print(sorted_by_keys(dictionary))
Add a comment
Know the answer?
Add Answer to:
Python 3. Define a function called sorted_by_keys that takes a dictionary as input and returns a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT