📘
List Operations
EasyPython Lists
Problem Statement
Perform common list operations.
Background
Python lists support many operations:
- Append: lst.append(item)
- Extend: lst.extend([items])
- Insert: lst.insert(index, item)
- Remove: lst.remove(item)
- Pop: lst.pop(index)
- Slice: lst[start:end]
Your Task
Write a function list_stats(numbers) that computes statistics about a list of numbers.
Output Format
Return a dictionary with:
- "length": Number of elements
- "sum": Sum of all elements
- "min": Minimum value
- "max": Maximum value
- "first_three": First 3 elements as list
- "last_three": Last 3 elements as list
- "sorted": Sorted list (ascending)
Example:
Input:
[5, 2, 8, 1, 9, 3]
Output:
{'length': 6, 'sum': 28, 'min': 1, 'max': 9, 'first_three': [5, 2, 8], 'last_three': [1, 9, 3], 'sorted': [1, 2, 3, 5, 8, 9]}Reasoning:
len() for length, sum() for sum, min()/max() for extremes, slicing for portions
Constraints:
- List will have at least 3 elements
- All elements are integers
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.