Saturday, June 22, 2024

📑 Global Variables in Lambda Functions

📑 Task

1) What object does this specific function modify and
what will the code print when the mini program runs?
2) Change this code snippet so that: a) the function can be used to generate Fibonacci sequences
independently, without relying on a global state
b) it returns only the n-st number of the sequence

📑 Answer

1) The function changes the global variable with
the initial value "empty list" by iterative appending
The result of the launch is a printout of a list
(the first ten numbers of the Fibonacci series)
2)

Thursday, June 13, 2024

📑 Custom Dictionaries

📑 Task

1) Describe the properties of the created custom dictionary
2) Define another dictionary in a similar way but with other properties
Your dictionary can have a list as a value only where it's necessary
That is, only where several values correspond to one key
in the definding process

📑 Answer

1) - **Key-Value Mapping**:
The dictionary maps integer keys to their corresponding binary string
representation, padded with leading zeros to a fixed length of 16 bits.
- **Automatic Conversion**:
When setting a new key-value pair using the `__setitem__` method,
the integer key is automatically converted to its binary string
representation before being stored in the dictionary.
- **Inheritance**:
By inheriting from `UserDict`, the `IntBinDict` class inherits
all the methods and properties of the built-in `dict` type,
allowing for seamless integration with existing Python code
that expects a dictionary-like object.
2)

Tuesday, June 4, 2024

📑 Items not Defined in the Dictionary

📑 Task

1) What element removing is fundamentally different from
all others for dictionary in this code fragment?
2) Suggest programs to access elements that do not exist
in the dictionary without causing an error

📑 Answer

1) Deleting "11" is different from all others, since such a key
was not defined in the dictionary
2)