Emulating Container Length (__len__)

Medium Magic Methods & Operator Overloading
Solve in Playground →

Problem Statement

Create a `Library` class that is initialized with a list of books. Overload the `__len__` method to return the count of the books in the list. Read a comma-separated list of strings, pass it to the library, and print `len(library)`.

Input Format

A single line of comma-separated strings.

Output Format

Print 'Total Books: [count]'.

Constraints

None

Sample Input

Dune,1984,Foundation

Sample Output

Total Books: 3

Explanation

By implementing `__len__`, custom classes can integrate seamlessly with Python's built-in `len()` function.

Starter Code

class Library:
    # Define __init__ taking a list, and __len__
    pass

if __name__ == '__main__':
    books_input = input().split(',')
    # Instantiate and print length
    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