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

Резултати

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

Пребарај: #sourceofthenile

当前筛选 #sourceofthenile清除筛选

🌊 ETHIOPIA: AFRICA'S WATER TOWER ኢትዮጵያ፡ የአፍሪካ የውሃ ማማ ЭФИОПИЯ: ВОДОНАПОРНАЯ БАШНЯ АФРИКИ Where legends begin - where life flows! 💙 ━━━━━━━━━━━━━━━━ 💙 LAKE TANA (ጣና ሀይቅ) - SOURCE OF THE NILE This is where Africa's greatest river is born: 🌊THE BLUE NILE: • Ethiopia provides 85% of the Nile's water! • 3,600 km² of pristine water • Flows 1,450 km from Tana to Sudan • "አባይ ወንዝ" (Abay) - Mother of Rivers 🏝️37 ISLAND MONASTERIES: • Some over 800 years old • Ancient manuscripts preserved • Traditional papyrus boats (tankwa) still used • Living history on water "The Blue Nile carries Ethiopia's gift to Africa and the world"🌍💙 ━━━━━━━━━━━━━━━━ 🏞️ GREAT RIFT VALLEY LAKES የሪፍት ሸለቆ ሀይቆች Nature's masterpieces: 🌅LAKE LANGANO: • Only swimmable rift lake! • Black volcanic beaches • Resort paradise 🦩LAKE ABIJATA & SHALA: • Thousands of pink flamingos • Alkaline waters = unique ecosystem • National Park protection • Photographers' dream 💚LAKE ZIWAY: • Thriving fishing communities • 300+ bird species • Fresh tilapia straight from water 🌋LAKE CHAMO: • "Crocodile market" - hundreds sunbathing! • Giant Nile crocodiles (6+ meters!) • Hippo pods & boat safaris Africa's Great Rift Valley creates magic in Ethiopia!✨ ━━━━━━━━━━━━━━━━ 💧 THE WATER TOWER OF AFRICA 🌍THE NUMBERS: • 12 major river basins • 11 lakes (8 in Rift Valley) • 122 billion m³ annual water resources • 85% of Nile water from Ethiopia • Water source for 11 African countries "ውሃችን የአፍሪካ ህይወት ነው" (Our water is Africa's life) ━━━━━━━━━━━━━━━━ 🌱 PROTECTING THE SOURCE Conservation efforts: ✅ Reforestation (billions of trees!) ✅ Lake protection zones ✅ Sustainable fishing ✅ Community conservation ✅ Research programs Preserving water = preserving life for all Africa💚 ━━━━━━━━━━━━━━━━ 🎒 EXPERIENCE ETHIOPIA'S WATERS Must-visit: 🚣LAKE TANA: • Island monastery tours • Traditional tankwa boats • Blue Nile Falls nearby • Coffee ceremony on shore ☕ 🏖️RIFT VALLEY CIRCUIT: • Beach resorts at Langano • Flamingo watching at Abijata • Crocodile tours at Chamo • Bird watching paradise 📸BLUE NILE FALLS: • "Tis Issat" (ጥስ እሰት) - "Water that Smokes" • 400m wide in rainy season • Rainbow mist all day • One of Africa's most spectacular waterfalls ━━━━━━━━━━━━━━━━ 🌊 WHY THIS MATTERS FOR ETHIOPIA: 💧 Water security for 120+ million 🌾 Agriculture & food production ⚡ Hydropower generation 🎣 Fishing community livelihoods FOR AFRICA: 🌍 Life source for Egypt, Sudan, South Sudan 💚 Regional water cooperation 🤝 Shared prosperity FOR THE WORLD: 🌱 Sustainable water management model 🦩 Biodiversity conservation 📚 Ancient wisdom meets modern stewardship ━━━━━━━━━━━━━━━━ 💙 FUN FACTS: 🤯 Ancient Egyptians called Ethiopia "Land of Gods"! 🤯 Lake Tana at 1,788m altitude - "highland sea" 🤯 Blue Nile's name from black sediment that looks blue 🤯 Some monasteries have 1300s manuscripts! 🤯 Rift Valley = tectonic plates separating! 🤯 Flamingos migrate in thousands - pink clouds! ━━━━━━━━━━━━━━━━ 🌊 FROM SOURCE TO SEA Ethiopia's water journey: Lake Tana → Blue Nile → Sudan → Egypt → Mediterranean 6,650 km sustaining 300+ million people "From Ethiopia's highlands - life flows to the world"🌍💙 ━━━━━━━━━━━━━━━━ NEXT:⚡ How Ethiopia turns water into POWER! ━━━━━━━━━━━━━━━━ 🌍 ETHIOPIA | ЭФИОПИЯ | ኢትዮጵያ 📱 Join us: @ethiopia telegram #EthiopiaWater#LakeTana#BlueNile#RiftValley#SourceOfTheNile#EthiopianLakes#AfricaWater#NileRiver