При проверке списка на пустоту часто используют два варианта:
✅ Pythonic способ:
if not mylist:
⏳ Медленный способ:
if len(mylist) == 0:
Хотя оба варианта работают, первый быстрее почти в 2 раза!
if not mylist быстрее, потому что: ✔️ Использует 2 инструкции виртуальной машины (LOAD_GLOBAL, TO_BOOL). ✔️ Инструкция TO_BOOL_LIST оптимизирована под списки и читает размер за 1 операцию.
if len(mylist) == 0медленнее, потому что: 📍 Требует 5 инструкций (LOAD_GLOBAL, LOAD_FAST, CALL, LOAD_CONST, COMPARE_OP). 📍 Вызывает len(), что добавляет функциональные вызовы и лишние обращения к памяти.
Вывод: Используйте if not mylist — это и короче, и быстрее. Особенно важно в критичных к скорости местах кода!
При проверке списка на пустоту часто используют два варианта:
✅ Pythonic способ:
if not mylist:
⏳ Медленный способ:
if len(mylist) == 0:
Хотя оба варианта работают, первый быстрее почти в 2 раза!
if not mylist быстрее, потому что: ✔️ Использует 2 инструкции виртуальной машины (LOAD_GLOBAL, TO_BOOL). ✔️ Инструкция TO_BOOL_LIST оптимизирована под списки и читает размер за 1 операцию.
if len(mylist) == 0медленнее, потому что: 📍 Требует 5 инструкций (LOAD_GLOBAL, LOAD_FAST, CALL, LOAD_CONST, COMPARE_OP). 📍 Вызывает len(), что добавляет функциональные вызовы и лишние обращения к памяти.
Вывод: Используйте if not mylist — это и короче, и быстрее. Особенно важно в критичных к скорости местах кода!
Just as the Bitcoin turmoil continues, crypto traders have taken to Telegram to voice their feelings. Crypto investors can reduce their anxiety about losses by joining the “Bear Market Screaming Therapy Group” on Telegram. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. How to create a business channel on Telegram? (Tutorial) Telegram offers a powerful toolset that allows businesses to create and manage channels, groups, and bots to broadcast messages, engage in conversations, and offer reliable customer support via bots. The imprisonment came as Telegram said it was "surprised" by claims that privacy commissioner Ada Chung Lai-ling is seeking to block the messaging app due to doxxing content targeting police and politicians.
from us