Why must dictionary keys be hashable, and what does that imply for lists?
Simple meaning
Dicts locate entries by hash then equality, so a key must implement a stable __hash__ and __eq__.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Python & Django questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Dicts locate entries by hash then equality, so a key must implement a stable __hash__ and __eq__.
Open the full page for Why, Steps, Example and Key takeaway.
A dict is flexible but typo-prone and has no field documentation.
Open the full page for Why, Steps, Example and Key takeaway.
CPython ints are arbitrary-precision
Open the full page for Why, Steps, Example and Key takeaway.
The default object is created once, at function definition, and shared across calls.
Open the full page for Why, Steps, Example and Key takeaway.
CPU-bound threads compete for the GIL, so they rarely use more than one core for Python bytecode.
Open the full page for Why, Steps, Example and Key takeaway.
Threads help when they spend time in I/O or in C code that releases the GIL, such as reading sockets, waiting on a database driver, or compressing in zlib.
Open the full page for Why, Steps, Example and Key takeaway.
threading shares one process and one GIL, so CPU-bound Python does not parallelize.
Open the full page for Why, Steps, Example and Key takeaway.
Open the full page for Why, Steps, Example and Key takeaway.
Use a nested factory: the outer function takes decorator arguments and returns the real decorator, which returns the wrapper.
Open the full page for Why, Steps, Example and Key takeaway.
If a class implements __init__ to receive the function and __call__ to run the wrapper, instances are callable decorators.
Open the full page for Why, Steps, Example and Key takeaway.
A wrapper calls the original and adds behavior
Open the full page for Why, Steps, Example and Key takeaway.
login_required checks request.user.is_authenticated and redirects or returns 403 depending on configuration.
Open the full page for Why, Steps, Example and Key takeaway.
A list comprehension builds the whole list in memory immediately.
Open the full page for Why, Steps, Example and Key takeaway.
send(value) resumes the generator and makes yield return that value inside the function.
Open the full page for Why, Steps, Example and Key takeaway.
You can yield lines or parsed chunks instead of reading the file into one string or list.
Open the full page for Why, Steps, Example and Key takeaway.
yield from subgen delegates iteration to another iterable or generator, forwarding values, send, and throw.
Open the full page for Why, Steps, Example and Key takeaway.
MRO is the linear order Python uses to find attributes on a class and its bases.
Open the full page for Why, Steps, Example and Key takeaway.
A diamond occurs when two bases share a common ancestor, so a method could be inherited twice.
Open the full page for Why, Steps, Example and Key takeaway.
ABCs, from abc.ABC, let you declare abstract methods that subclasses must implement.
Open the full page for Why, Steps, Example and Key takeaway.
@property turns a method into managed attribute access so callers use obj.x instead of obj.x().
Open the full page for Why, Steps, Example and Key takeaway.