Enabling Indexing (__getitem__, __setitem__)

Medium Magic Methods & Operator Overloading PRO
🔒 Login to Unlock

Problem Statement

Create a `CustomList` class that wraps a standard list. Overload `__getitem__` to read an element by index, and `__setitem__` to update an element by index. Read a list of integers, update a specific index with a new value, and print the updated list directly.

Input Format

Line 1: space-separated integers (the list). Line 2: target index. Line 3: new value.

Output Format

Print the retrieved value before updating, then print the entire raw list.

Constraints

Assume the index is always valid.

Sample Input

10 20 30
1
99

Sample Output

Old: 20
List: [10, 99, 30]

Explanation

These magic methods allow custom objects to support standard bracket indexing notation `obj[index]`.

Starter Code

class CustomList:
    # Define __init__, __getitem__, and __setitem__
    pass

if __name__ == '__main__':
    lst = list(map(int, input().split()))
    idx = int(input())
    new_val = int(input())
    # Manipulate CustomList using brackets and print
    pass

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