TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: from timeit import timeit def t1(): # складываем 10 строк через + из переменной t = 'text' for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t2(): # склеиваем список строк через метод join arr = ['text'] * 10 for _ in range(1000): s = ''.join(arr) def t3(): # складываем через + но не из переменной а непосредственно инлайн объекты for _ in range(1000): s = 'text' + 'text' + 'text' + ... # всего 10 раз Теперь каждую строку склейки запустим по 10М раз >>> timeit(t1, number=10000) 0.21951690399964718 >>> timeit(t2, number=10000) 1.4978306379998685 >>> timeit(t3, number=10000) 0.2213820789993406 Хм, а нам говорили что через "+" это плохо и медленно ))) 😁 Тут стоит учитывать, что речь идёт о склейке множества длинных строк. Давайте изменим условия: def t4(): t = 'text'*100 for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t5(): arr = ['text'*100] * 10 for _ in range(1000): s = ''.join(arr) def t6(): for _ in range(1000): s = 'text'*100 + 'text'*100 + ... # всего 10 раз >>> timeit(t4, number=10000) 12.795130728000004 >>> timeit(t5, number=10000) 2.642637542999182 >>> timeit(t6, number=10000) 0.2184546610005782 Вот, уже другой разговор, сразу видна разница, в среднем в 6 раз. Но погодите, почему последний тест t6() по скорости такой же как и t3()? Ведь строки теперь в 100 раз длиннее! Это вопросы оптимизации кода, какие простые изменения ускоряют или замедляют выполнение программы. Мы столкнулись с примером обхода обращения к переменной. Например, именно так работает директива #define в С++, во время компиляции подставляя значение переменной вместо ссылки на неё. В Python это тоже работает, но часто ли вы сможете встретить такой способ работы со строками? К сожалению, способ почти только теоретический. В целом, тесты показали то, что мы хотели. Делаем выводы самостоятельно. Полный листинг 🌍 #tricks

Резултати

Пронајдени 9 слични објави

Пребарај: #archipelago

当前筛选 #archipelago清除筛选
Amazing Geography 🌍

@amazingeo · Post #693 · 17.04.2026 г., 20:31

🌍 Indonesia is the world’s largest archipelago, made up of over 17,000 islands. Some, like Java, are densely populated, while others remain so remote they still hold undiscovered plant species. ✨ #archipelago⚡#islands⚡#biodiversity⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #609 · 02.02.2026 г., 20:31

🌍 Norway’s Lofoten Islands lie above the Arctic Circle but have surprisingly mild winters thanks to warm ocean currents, supporting thriving fishing villages on steep, rocky shores. ✨ #islands⚡#archipelago⚡#climate⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #349 · 08.10.2025 г., 20:31

🌍 The Philippines is the world’s second-largest archipelago, with over 7,600 islands. Many of its islands have never been officially named or mapped due to their remote locations. ✨ #islands⚡#archipelago⚡#mapping⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #119 · 26.08.2025 г., 09:12

🌍 The Svalbard Archipelago, north of mainland Norway, is the northernmost year-round inhabited place on Earth. It’s so remote that polar bears outnumber people here during much of the year. ✨ #archipelago⚡#islands⚡#Arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #156 · 01.09.2025 г., 13:12

🌍 Canada has more lakes than any other country, and many are so large they contain whole islands with their own lakes—making some islands-in-a-lake-on-an-island truly unique on Earth. ✨ #islands⚡#archipelago⚡#lakes⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #269 · 20.09.2025 г., 03:12

🌍 The Maldives is the world’s lowest country, with an average elevation of just 1.5 meters above sea level. Its coral islands are so flat that even small sea level rises can threaten their land. ✨ #islands⚡#archipelago⚡#sea⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #571 · 12.01.2026 г., 12:31

🌍 The remote Tristan da Cunha archipelago in the South Atlantic is the world’s most isolated inhabited island group—over 2,400 kilometers from the nearest mainland or neighboring islands. ✨ #islands⚡#archipelago⚡#remoteness⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #498 · 06.12.2025 г., 20:31

🌍 The Aegean Archipelago in the Mediterranean holds over 1,400 islands, yet only about 200 are inhabited. Many tiny isles remain wild, protecting rare plants and seabirds. ✨ #islands⚡#archipelago⚡#Mediterranean⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #531 · 23.12.2025 г., 12:31

🌍 The Faroe Islands in the North Atlantic have more sheep than people. This remote archipelago’s grassy cliffs and rugged fjords create perfect grazing land for thousands of hardy sheep. ✨ #islands⚡#archipelago⚡#northatlantic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​