🖥Хитрая задача на Python для продвинутых: словарь, который работает как список
Представь структуру данных, которая: • работает как dict — доступ по ключу • работает как list — доступ по индексу • сохраняет порядок вставки • поддерживает .index(key) и .key_at(i)
📌Задача: Реализуй класс IndexedDict, который делает всё это.
• Просто наследовать dict не получится — d[0] будет интерпретироваться как ключ, а не индекс • Придётся реализовать двойную логику доступа вручную • Нужно корректно поддержать __iter__, __getitem__, __len__ и др.
✅ Решение: ```python from collections.abc import MutableMapping
class IndexedDict(MutableMapping): def __init__(self): self._data = {} self._keys = []
• Отличная тренировка на переопределение магических методов • Часто встречается в фреймворках (Pandas, SQLAlchemy) • Тестирует знание ABC-классов (`collections.abc.MutableMapping`) • Полезно для построения кастомных структур данных
Хочешь версию с `__contains__`, `__reversed__`, типизацией и сериализацией — пиши 💬
🖥Хитрая задача на Python для продвинутых: словарь, который работает как список
Представь структуру данных, которая: • работает как dict — доступ по ключу • работает как list — доступ по индексу • сохраняет порядок вставки • поддерживает .index(key) и .key_at(i)
📌Задача: Реализуй класс IndexedDict, который делает всё это.
• Просто наследовать dict не получится — d[0] будет интерпретироваться как ключ, а не индекс • Придётся реализовать двойную логику доступа вручную • Нужно корректно поддержать __iter__, __getitem__, __len__ и др.
✅ Решение: ```python from collections.abc import MutableMapping
class IndexedDict(MutableMapping): def __init__(self): self._data = {} self._keys = []
• Отличная тренировка на переопределение магических методов • Часто встречается в фреймворках (Pandas, SQLAlchemy) • Тестирует знание ABC-классов (`collections.abc.MutableMapping`) • Полезно для построения кастомных структур данных
Хочешь версию с `__contains__`, `__reversed__`, типизацией и сериализацией — пиши 💬
Ukrainian President Volodymyr Zelensky said in a video message on Tuesday that Ukrainian forces "destroy the invaders wherever we can." At the start of 2018, the company attempted to launch an Initial Coin Offering (ICO) which would enable it to enable payments (and earn the cash that comes from doing so). The initial signals were promising, especially given Telegram’s user base is already fairly crypto-savvy. It raised an initial tranche of cash – worth more than a billion dollars – to help develop the coin before opening sales to the public. Unfortunately, third-party sales of coins bought in those initial fundraising rounds raised the ire of the SEC, which brought the hammer down on the whole operation. In 2020, officials ordered Telegram to pay a fine of $18.5 million and hand back much of the cash that it had raised. At its heart, Telegram is little more than a messaging app like WhatsApp or Signal. But it also offers open channels that enable a single user, or a group of users, to communicate with large numbers in a method similar to a Twitter account. This has proven to be both a blessing and a curse for Telegram and its users, since these channels can be used for both good and ill. Right now, as Wired reports, the app is a key way for Ukrainians to receive updates from the government during the invasion. "There are a lot of things that Telegram could have been doing this whole time. And they know exactly what they are and they've chosen not to do them. That's why I don't trust them," she said. In December 2021, Sebi officials had conducted a search and seizure operation at the premises of certain persons carrying out similar manipulative activities through Telegram channels.
from sg