Part of the series

Several example codes

~1 min read • Updated Sep 24, 2025

Program Overview

This Python program analyzes a list of rivers, each with coverage percentage and length.
It filters rivers that cover more than half of the plateau and identifies the one with the greatest length.


Python Code:


# Sample data: river name, coverage (%), and length (km)
rivers = [
    {"name": "River A", "coverage": 40, "length": 600},
    {"name": "River B", "coverage": 55, "length": 720},
    {"name": "River C", "coverage": 70, "length": 680},
    {"name": "River D", "coverage": 30, "length": 500}
]

# Filter rivers that cover more than 50% of the plateau
filtered = [r for r in rivers if r["coverage"] > 50]

# Find the river with the longest length
longest = max(filtered, key=lambda r: r["length"])

# Display the result
print("Longest river covering the plateau:", longest["name"])

Sample Output:


Longest river covering the plateau: River B

Explanation:

- The list rivers contains dictionaries with coverage and length data
- Rivers with coverage greater than 50% are selected using a list comprehension
- The max() function identifies the river with the highest length
- The name of the longest qualifying river is printed


Written & researched by Dr. Shahin Siami