🖥Хитрая задача на 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__`, типизацией и сериализацией — пиши 💬
Markets continued to grapple with the economic and corporate earnings implications relating to the Russia-Ukraine conflict. “We have a ton of uncertainty right now,” said Stephanie Link, chief investment strategist and portfolio manager at Hightower Advisors. “We’re dealing with a war, we’re dealing with inflation. We don’t know what it means to earnings.” Telegram was co-founded by Pavel and Nikolai Durov, the brothers who had previously created VKontakte. VK is Russia’s equivalent of Facebook, a social network used for public and private messaging, audio and video sharing as well as online gaming. In January, SimpleWeb reported that VK was Russia’s fourth most-visited website, after Yandex, YouTube and Google’s Russian-language homepage. In 2016, Forbes’ Michael Solomon described Pavel Durov (pictured, below) as the “Mark Zuckerberg of Russia.” Additionally, investors are often instructed to deposit monies into personal bank accounts of individuals who claim to represent a legitimate entity, and/or into an unrelated corporate account. To lend credence and to lure unsuspecting victims, perpetrators usually claim that their entity and/or the investment schemes are approved by financial authorities. The regulator said it has been undertaking several campaigns to educate the investors to be vigilant while taking investment decisions based on stock tips. This ability to mix the public and the private, as well as the ability to use bots to engage with users has proved to be problematic. In early 2021, a database selling phone numbers pulled from Facebook was selling numbers for $20 per lookup. Similarly, security researchers found a network of deepfake bots on the platform that were generating images of people submitted by users to create non-consensual imagery, some of which involved children.
from tr