Dictionary Sorting

Medium Dictionaries PRO
🔒 Login to Unlock

Problem Statement

Write a Python program to sort a dictionary by its values in ascending order and print the resulting sorted dictionary items as a list of tuples.

Input Format

Space-separated key-value pairs with integer values.

Output Format

Print the sorted list of tuples.

Constraints

Non-empty dictionary

Sample Input

banana 3 apple 1 cherry 2

Sample Output

[('apple', 1), ('cherry', 2), ('banana', 3)]

Explanation

Use `sorted()` with `key=lambda x: x[1]` on `d.items()`.

Starter Code

def sort_by_value(d):
    # Write your code here
    pass

raw = input().split()
d = {raw[i]: int(raw[i+1]) for i in range(0, len(raw), 2)}
print(sort_by_value(d))

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used