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)

No comments:

Post a Comment