5 questions across Easy, Medium, and Hard levels
Lists are mutable (can be changed after creation) while tuples are immutable (cannot be changed). Lists use square brackets [] while tuples use parentheses (). Tuples are generally faster and use less memory. Lists are used when you need a collection that will be modified, tuples when the data should not change.
A lambda function is an anonymous (unnamed) function that can have any number of arguments but only one expression. Syntax: lambda arguments: expression. Example: double = lambda x: x * 2. Lambda functions are commonly used with map(), filter(), and sorted() functions.
List comprehension provides a concise way to create lists. Syntax: [expression for item in iterable if condition]. Example: squares = [x**2 for x in range(10) if x % 2 == 0] creates a list of squares of even numbers from 0-9. It's more readable and faster than traditional for loops.
*args allows you to pass a variable number of positional arguments. **kwargs allows you to pass a variable number of keyword arguments as a dictionary. Example: def func(*args, **kwargs): pass. *args stores values as a tuple, **kwargs stores key-value pairs as a dict.
The GIL is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecode simultaneously. This means true multi-threading is limited in CPython. For CPU-bound tasks, use multiprocessing instead. For I/O-bound tasks, threading still works well since threads release the GIL during I/O operations.