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

Резултати

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

Пребарај: #chemistry

当前筛选 #chemistry清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #1331 · 07.03.2026 г., 12:11

🌎 Ancient Egypt’s ability to make “Egyptian blue,” the first synthetic pigment, was lost for centuries. This stable, vivid blue was made from copper, silica, and lime, fired at high temperatures. Modern chemists only rediscovered the process in the early 19th century using advanced analysis of ancient artifacts. ✨ #history⚡#archaeology⚡#chemistry 👉subscribe Interesting Planet 👉more Channels ​

德国化学家凯库勒(Kekulé)做梦,梦到蛇咬住自己的尾巴首尾相接,悟出了苯的结构是环状,醒来之后就写了论文转化为化学研究成果。我刚才做了一晚上梦,梦里跑了很多地方,办了很多事,醒了之后却不记得任何细节了,只觉得浑身疲惫像是真的刚跑完步。虽然身体疲惫但是脑子清醒了,感觉没法再继续睡了,上网随便看看。 #Chemistry#Feeling

Interesting Planet 🌍

@interesting_planet_facts · Post #598 · 21.08.2025 г., 00:22

🌎 The pyura chilensis, also known as the “living rock,” is a sea creature found on Chile’s coast that looks like a stone but bleeds bright red when cut. Its tunicate body is actually a filter feeder packed with vanadium, a rare element in animals. ✨ #ocean⚡#animals⚡#chemistry 👉subscribe Interesting Planet

Amazing Geography 🌍

@amazingeo · Post #351 · 09.10.2025 г., 15:31

🌍 In Africa’s Lake Natron, minerals in the water turn it bright red during the dry season. The lake’s extreme chemistry preserves animal remains, creating eerie natural “statues.” ✨ #lakes⚡#Africa⚡#chemistry⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40744 · 06.03.2026 г., 16:17

Today in history. On March 6, 1869, Russian chemist Dmitri Mendeleev presented the first periodic table of elements, titled "The Dependence Between the Properties of the Atomic Weights of the Elements," to the Russian Chemical Society. He organized 63 known elements by atomic weight, leaving gaps for undiscovered elements like gallium and germanium. @googlefactss#chemistry#history#todayinhistory [read more...]

Interesting Planet 🌍

@interesting_planet_facts · Post #1313 · 24.02.2026 г., 12:11

🌎 In 1867, Swedish chemist Alfred Nobel invented dynamite by stabilizing volatile nitroglycerin with an absorbent clay called kieselguhr. This made blasting much safer for construction and mining. Nobel later used his dynamite fortune to establish the Nobel Prizes in 1895. ✨ #inventions⚡#chemistry⚡#history 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #848 · 02.10.2025 г., 18:11

🌎 The accidental invention of safety glass happened in 1903, when French chemist Édouard Bénédictus dropped a glass flask coated with plastic cellulose nitrate. Rather than shattering, the glass cracked but held together, inspiring shatter-resistant windshields. By 1927, safety glass became standard in automobile manufacturing. ✨ #inventions⚡#chemistry⚡#history 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #392 · 23.07.2025 г., 02:22

🌎 In the dark waters of the Black Sea, ancient bacteria can “eat” toxic hydrogen sulfide gas, turning it into harmless sulfate. This vital process keeps deep sea life possible in these oxygen-poor zones. ✨ #bacteria⚡#chemistry⚡#ocean 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #377 · 21.07.2025 г., 17:22

🌎 Ancient Greek fire, known as "Greek fire," was a weapon that could burn even on water. This flammable liquid, projected from tubes, terrified enemies at sea and kept its formula a closely guarded secret, lost to history. ✨ #history⚡#chemistry⚡#warfare 👉subscribe Interesting Planet

International News

@intnewsagency · Post #9350 · 23.04.2026 г., 08:28

Russia leads at the 60th International Mendeleev Chemistry Olympiad in Moscow, winning 7 gold and 8 silver medals. All 15 Russian participants received awards, showcasing top university-level skills. Vice Premier Chernyshenko called the result outstanding, while Minister Kravtsov highlighted systematic preparation. The Olympiad is part of the Science and Technology Decade running until 2031. This victory underscores Russia’s strength in chemistry education and research. #Russia#MendeleevOlympiad#Chemistry#Science The main news of Russia and the world ishere.

Universe Mysteries 🪐

@cosmomyst · Post #31 · 30.07.2025 г., 04:00

🪐 Encircling the young star TW Hydrae, a vast protoplanetary disk glows with mysterious gaps and spiral patterns sculpted by the formation of new worlds. Observations with ALMA revealed complex chemical fingerprints in the disk, including cyanide compounds that could play a role in the origins of life. ✨ #TWHydrae⚡#protoplanetary⚡#chemistry 👉subscribe Universe Mysteries

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