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

Резултати

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

Пребарај: #sustainablefarming

当前筛选 #sustainablefarming清除筛选
Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40393 · 23.12.2025 г., 11:03

Vegan diets can help the environment, but large-scale plant farming can hurt soil, wildlife, and cause pollution. Synthetic fertilizers used in farming can damage oceans and soil. Animal farming done the right way helps soil, supports wildlife, and uses natural manure. Eating animal foods gives important nutrients like B12 and iron that plants don’t provide. 🌿🐄🌎 [Read more] @googlefactss #Vegan#Environment#SoilHealth#AnimalFarming#Nutrition#SustainableFarming#EcoFriendly

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40869 · 28.03.2026 г., 15:03

A single tree, called the Tree of 40 Fruits, holds the record for the most varieties of fruit on one tree. Created by Sam Van Aken, it has 40 different types of stone fruits. These include peaches, plums, apricots, almonds, and cherries. The tree was made using grafting, where branches from different fruit trees are attached to one rootstock. This project shows how diverse fruit can grow on a single tree. 🍑🌳🍒🍎🍏 [Read more] @googlefactss #TreeOf40Fruits#Grafting#SamVanAken#FruitVarieties#GuinnessWorldRecords#AmazingNature#SustainableFarming

Venture Village Wall 🦄

@venturevillagewall · Post #3612 · 21.12.2024 г., 10:21

Kaly Group Funding Update Kaly Group has raised $379.64K in funding, as of December 19, 2024. This Scottish initiative focuses on sustainable seaweed farming, delivering training and support to local communities while promoting the ecological benefits of kelp cultivation. #KalyGroup#Funding#SustainableFarming#Seaweed#Ecology#MarineEnvironment#CommunitySupport#Scotland#Kelp#Entrepreneurs

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40860 · 25.03.2026 г., 23:01

Hussam Saraf set a record for the most species grafted onto a single tree. His tree has 5 different species: plum, apricot, almond, peach, and cherry. The tree was made by grafting branches from these species onto one trunk. This represents diversity and peaceful coexistence, as the fruits symbolize how different cultures can live together. 🌳🍑🍒 [Read more] @googlefactss #Grafting#PeacefulCoexistence#HussamSaraf#FiveSpeciesTree#FruitDiversity#GuinnessWorldRecords#AmazingNature#SustainableFarming