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

Пребарај: #coha

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

@addisstandardeng · Post #21247 · 30.01.2026 г., 09:14

News: #AU Chairperson calls for maximum restraint amid renewed tensions in #Tigray The Chairperson of the African Union Commission, Mahmoud Ali Youssouf, has urged all parties in #Ethiopia’s Tigray region to exercise maximum restraint as tensions rise and reports emerge of renewed clashes in parts of the region. In a statement issued on Friday, the AU Commission said its Chairperson is closely monitoring developments in Tigray and expressed deep concern over recent developments. He re-emphasized the paramount importance of preserving the “hard-won gains” achieved under the African Union-led Permanent Cessation of Hostilities Agreement (#COHA) signed between the federal government and the Tigray People’s Liberation Front (#TPLF) in Pretoria on 2 November 2022. The Chairperson called on all parties to refrain from actions that could undermine confidence and to resolve outstanding issues through constructive dialogue, in full adherence to both the ..... Read more: https://addisstandard.com/?p=54840

Addis Standard

@addisstandardeng · Post #21310 · 04.02.2026 г., 15:20

News: #AU monitoring team returns to #Mekelle after tensions renew focus on #Pretoria agreement An advance team of African experts under the African Union’s Monitoring, Verification and Compliance Mechanism (#AU-MVCM) has arrived in Mekelle, resuming its “mandate of monitoring the implementation” of the Permanent Cessation of Hostilities Agreement (#COHA), the AU Commission’s Political Affairs, Peace and Security Department said on today. According to the Commission, the team redeployed after an “administrative break” to resume their mandate the office said was “crucial” to the implementation of the of the COHA, signed between the federal government and the #Tigray People’s Liberation Front (#TPLF) in November 2022. The resumption of the task comes amid concerns over renewed tensions, clashes and drone strikes in parts of Tigray. Last week, the AU Commission Chairperson Mahmoud Ali Youssouf .... Read more: https://addisstandard.com/?p=54994

Addis Standard

@addisstandardeng · Post #21388 · 12.02.2026 г., 15:01

News: #TPLF says it ‘will not stay idle’ if #Pretoria deal is breached, urges AU, US, EU to move beyond concern statements The chairman of the Tigray People’s Liberation Front (TPLF), Debretsion Gebremichael (PhD), has warned that the party “will not stay idle” if the Pretoria Cessation of Hostilities Agreement (#CoHA) is breached and the group comes under attack, while dismissing claims that it has been “weakened and dispersed.” He also urged international actors including the African Union (#AU), the #United_States, and the European Union (#EU) to move beyond expressions of concern and take concrete action to safeguard the fragile peace process. Speaking at a press briefing today, Debretsion rejected assertions that the TPLF has lost cohesion. “They say we are weakened and dispersed. But our answer is: we are not dispersed when it comes to our survival and security,” he said. Debretsion also said he has been in frequent contact with representatives.... Read more: https://addisstandard.com/?p=55172

Addis Standard

@addisstandardeng · Post #21252 · 30.01.2026 г., 12:56

News: #Tigray opposition parties urge international mediators to intervene as tensions raise fears of renewed war Several Tigray-based opposition political parties have issued separate open letters warning of an imminent risk of renewed conflict in the region and calling on international mediators and guarantors of the Cessation of Hostilities Agreement (#CoHA) to take urgent preventive action. Salsay Weyane Tigray (#SaWeT) and the Tigray Independence Party (#TIP), in letters addressed to the #United_Nations, the African Union (#AU), the #United_States, the #European_Union, and other guarantors and facilitators of the Pretoria peace agreement, expressed deep concern over what they described as escalating political and military tensions that could unravel the fragile peace in Tigray. In its open letter, SaWeT warned that the region is “on the brink of an absolutely preventable disaster,” saying that a growing military confrontation threatens the collapse of ….. Read more: https://addisstandard.com/?p=54847