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

Резултати

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

Пребарај: #volcanoes

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

@amazingeo · Post #424 · 30.10.2025 г., 20:31

🌍 One of the youngest islands on Earth, Hunga Tonga-Hunga Haʻapai, formed in 2015 after an undersea volcanic eruption. New land like this is rare and offers scientists a natural laboratory. ✨ #islands⚡#volcanoes⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #500 · 04.08.2025 г., 20:22

🌎 The maleo bird of Sulawesi uses volcanic heat to hatch its eggs! It buries them in warm sand or soil, letting Earth's warmth do the work, and the chicks dig themselves out and run off ready to face the world—a rare strategy among birds. ✨ #volcanoes⚡#birds⚡#adaptation 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #490 · 03.08.2025 г., 03:22

🌎 Towering above Tanzania, Mount Kilimanjaro is the world’s tallest free-standing mountain. Unlike mountain ranges, it rises alone from the plains, formed by ancient volcanic eruptions. Its snowy peak is a surprising sight just south of the equator. ✨ #geology⚡#volcanoes⚡#Africa 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1221 · 14.01.2026 г., 12:11

🌎 Rising from an ancient volcanic crater, Aogashima is a remote Japanese island village with about 170 residents. The island’s school has fewer than 10 students, and access is by boat or helicopter due to rough seas and no airport. ✨ #geography⚡#settlements⚡#volcanoes 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #352 · 09.10.2025 г., 18:31

🌍 Mount Etna in Italy is one of the world’s most active volcanoes, but it’s also growing taller each year as repeated eruptions pile new layers of lava onto its summit. ✨ #mountains⚡#volcanoes⚡#geology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1147 · 20.12.2025 г., 18:11

🌎 Layers of volcanic ash preserved in sediments create natural records of Earth's explosive history. By analyzing ash layers, scientists can pinpoint ancient eruptions and trace how ash traveled across continents. Some distant ash deposits reveal supervolcano eruptions that spread material for thousands of kilometers. ✨ #volcanoes⚡#geology⚡#sediments 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #461 · 29.07.2025 г., 20:22

🌎 At the heart of Africa, Lake Nyos hides a deadly secret—an underwater layer of carbon dioxide gas that once erupted, suffocating everything nearby in 1986. This rare “limnic eruption” happens when gas builds up at depth and suddenly bursts to the surface, releasing an invisible, odorless cloud with devastating effects. ✨ #volcanoes⚡#disasters⚡#geology 👉subscribe Interesting Planet

Amazing Geography 🌍

@amazingeo · Post #345 · 07.10.2025 г., 20:31

🌍 Earth’s mountain-building processes are still active—over 80% of volcanoes erupt near tectonic plate boundaries, constantly creating new land and even islands in the world’s oceans. ✨ #geology⚡#volcanoes⚡#oceans⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1229 · 16.01.2026 г., 22:11

🌎 Around 252 million years ago, the Permian-Triassic extinction wiped out about 90% of marine species and 70% of land vertebrates. Massive volcanic eruptions in Siberia released greenhouse gases that drove rapid global warming, ocean acidification, and low oxygen levels—making it the largest extinction event in Earth's history. ✨ #extinction⚡#volcanoes⚡#paleoclimate 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1172 · 29.12.2025 г., 12:11

🌎 In northeast Azerbaijan, the Gobustan Mud Volcanoes regularly erupt with cool, viscous mud instead of lava. These eruptions can blast columns up to 200 meters high. About half of the world’s estimated 1,000 mud volcanoes are concentrated in this region, producing unique surface features and even spontaneous flames when natural gas ignites. ✨ #Azerbaijan⚡#volcanoes⚡#geology 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #466 · 20.11.2025 г., 20:31

🌍 The ring-shaped chain of volcanoes called the "Ring of Fire" circles the Pacific Ocean, hosting about 75% of all active volcanoes on Earth and causing frequent earthquakes and eruptions. ✨ #volcanoes⚡#mountains⚡#tectonics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #121 · 26.08.2025 г., 16:12

🌍 Mount Erebus in Antarctica is one of the world’s southernmost active volcanoes. Its lava lake stays liquid year-round, despite harsh temperatures that often plunge far below freezing. ✨ #volcanoes⚡#Antarctica⚡#mountains⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

ПретходнаСтраница 1 од 3Следна