Nested List Comprehensions
Mon 10 August 2026
matrix = [[i * j for j in range(3)] for i in range(3)]
Score: 10
Category: chapter9_list_comprehension
Read Morematrix = [[i * j for j in range(3)] for i in range(3)]
Score: 10
Category: chapter9_list_comprehension
Read Morepip install requests
import requests
response = requests.get("https://api.example.com")
print(response.status_code)
Score: 15
Category: chapter10_modules_and_packages
Read Moreclass Vector:
def __init__(self, x):
self.x = x
def __add__(self, other):
return Vector(self.x + other.x)
v1 = Vector(10)
v2 = Vector(20)
v3 = v1 + v2
print(v3.x) # Output: 30
30
Score: 10
Category: chapter5_operator_overloading
Read Morefrom functools import lru_cache
@lru_cache(maxsize=None)
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
print(fibonacci(30)) # Optimized recursion
832040
Score: 10
Category: chapter8_recursion
Read Moreclass A:
def display(self):
print("From A")
class B:
def display(self):
print("From B")
class C(A, B):
pass
obj = C()
obj.display()
From A
Score: 10
Category: chapter3_multiple_inheritance
Read Moreclass Calculator:
def __init__(self, value):
self.value = value
def __truediv__(self, other):
return self.value / other.value
c1 = Calculator(100)
c2 = Calculator(4)
print(c1 / c2) # Output: 25.0
25.0
Score: 10
Category: chapter5_operator_overloading
Read Moreclass Point:
def __init__(self, x):
self.x = x
def __eq__(self, other):
return self.x == other.x
p1 = Point(5)
p2 = Point(5)
print(p1 == p2) # True
True
Score: 10
Category: chapter5_operator_overloading
Read Moreclass Counter:
def __init__(self, value):
self.value = value
def __iadd__(self, other):
self.value += other
return self
c = Counter(10)
c += 5
print(c.value) # Output: 15
15
Score: 10
Category: chapter5_operator_overloading
Read Moreclass Score:
def __init__(self, marks):
self.marks = marks
def __lt__(self, other):
return self.marks < other.marks
def __gt__(self, other):
return self.marks > other.marks
s1 = Score(85)
s2 = Score(70)
print(s1 > s2) # True
True
Score: 10
Category: chapter5_operator_overloading
Read Moreclass Repeater:
def __init__(self, text):
self.text = text
def __mul__(self, times):
return self.text * times
r = Repeater("AI ")
print(r * 3) # Output: AI AI AI
AI AI AI
Score: 10
Category: chapter5_operator_overloading
Read More