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 слични објави

Пребарај: #kenyan

当前筛选 #kenyan清除筛选
Addis Standard

@addisstandardeng · Post #21462 · 20.02.2026 г., 08:42

#Russia denies of recruiting #Kenyan citizens for war in #Ukraine The Embassy of the Russian Federation in Kenya has rejected allegations that it was involved in recruiting Kenyan citizens to fight in the conflict in Ukraine, describing the claims as part of a “dangerous and misleading propaganda campaign.” In a press release issued on February 19, the embassy said it had observed with “great concern” reports circulating in Kenyan media and public discourse regarding Kenyan nationals who allegedly traveled to Russia, joined the Armed Forces of the Russian Federation, and participated in combat operations in Ukraine. The statement comes after an intelligence official briefing presented to Kenya’s Parliament reported that 89 Kenyans were confirmed on the front line, 39 were hospitalized, and 28 were missing in action. https://addisstandard.com/?p=55260

Addis Standard

@addisstandardeng · Post #21908 · 01.04.2026 г., 16:28

Shipping disruptions strand 8 million kg of #Kenyan tea in #Mombasa as #US-#Israel war with #Iran hits exports Disruptions to global shipping routes linked to the ongoing war between the United States, Israel, and Iran have left nearly eight million kilograms of tea stranded in warehouses in Mombasa, threatening export earnings and farmer incomes, according to the East Africa Tea Traders Association. George Omuga, managing director of the association that runs the Mombasa tea auction, told Reuters that losses have been accumulating at roughly $8 million per week since 01 March. “The current conflict in the Middle East has had a direct impact, a negative impact on this auction,” Omuga said, noting that no tea shipments were currently leaving for Middle Eastern markets, which account for 20–25% of Kenya’s tea exports. https://x.com/addisstandard/status/2039378986518626404?s=20

Addis Standard

@addisstandardeng · Post #21163 · 23.01.2026 г., 09:22

News: #IMF-backed forex reforms cost #Ethiopia $2.6 billion in central bank losses Ethiopia’s central bank, the National Bank of Ethiopia (#NBE), has recorded losses equivalent to $2.6 billion following the country’s shift from a fixed to a market-based foreign exchange regime in July 2024, according to audited financial statements cited by the #Kenyan outlet The EastAfrican. NBE said it incurred 407.1 billion birr in foreign exchange losses during the financial year ending June 30, 2025, largely due to the revaluation of its foreign currency assets and liabilities after the exchange rate realignment. Foreign exchange losses rose sharply to 445.23 billion birr, from 38.13 billion birr the previous year. The surge pushed the National Bank of Ethiopia’s overall operating loss to 428.56 billion birr, up from 10.51 billion birr a year earlier, and drove the Bank into a negative equity position of 380 billion birr, raising concerns over its ability to continue... Read more: https://addisstandard.com/?p=54706

Addis Standard

@addisstandardeng · Post #21956 · 07.04.2026 г., 05:28

#UN envoy meets RSF leader in #Nairobi to discuss de-escalation in #Sudan The United Nations Personal Envoy for Sudan, Pekka Haavisto, met with Rapid Support Forces (#RSF) commander Mohamed Hamdan “Hemetti” Dagalo in Nairobi on Monday to discuss practical avenues for de-escalation. The meeting in the #Kenyan capital is part of Haavisto’s inaugural regional tour. It follows recent discussions in Khartoum with the President of the Transitional Sovereign Council, General Abdel Fattah al-Burhan, as the UN seeks to mediate an end to the nearly three-year-old conflict. UN spokesperson Stéphane Dujarric described the talks as a “constructive opportunity” to exchange views on protecting civilians. He noted that all stakeholders engaged by Haavisto have expressed readiness to cooperate with the world body. “This is encouraging and must swiftly translate into concrete progress towards ending..... https://www.facebook.com/AddisstandardEng/posts/pfbid0KVXwXxdPxbctPJpW5qK7Kwkw63bPeXrmU7q7Bjab37CvbqfZT7SuvSHFZqa4GrN2l