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

Резултати

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

Пребарај: #ramaphosa

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

@addisstandardeng · Post #21140 · 21.01.2026 г., 07:56

News: #Somalia, #South_Africa discuss security, regional stability Somali President #Hassan_Sheikh Mohamud on Tuesday held a telephone conversation with South African President Cyril #Ramaphosa, during which the two leaders discussed strengthening bilateral relations and expanding cooperation on peace and security, trade and investment, and regional stability. According to Somalia’s state news agency SONNA, the talks also covered key regional and continental developments, with both leaders reaffirming their commitment to #African solidarity and shared prosperity. Recently reports indicate that Somalia intensifies diplomatic relations with different countries. Yesterday SONNA reported.that Somalia has signed a defence cooperation agreement with #Qatar, days after formally terminating all existing security and defence arrangements with the United Arab Emirates (#UAE). The agreement was... https://web.facebook.com/AddisstandardEng/posts/pfbid0APngK9nL83rpkiaz2ADgk3Fhm1cZKE3Utxx6mMTkWx8RgG7w4yTYz191C3C5g6uAl

Addis Standard

@addisstandardeng · Post #21685 · 12.03.2026 г., 05:29

#South_Africa deploys soldiers to the streets to tackle organized and violent crime Soldiers were deployed to the streets of South Africa’s biggest city Wednesday in an effort to help police fight gang violence and illegal mining. It was the first major deployment since President Cyril #Ramaphosa said in his annual speech to the nation last month that he would use the army against organized crime, which he called the greatest threat to democracy and the country’s economic development. Soldiers jumped from vehicles and entered apartment blocks as military vehicles moved through the #Riverlea and #Westbury suburbs of #Johannesburg. Many residents of Riverlea expressed relief to see soldiers deployed to stem the violence. One resident, Pearl Hilma, told The Associated Press that she supports the crackdown “because there’s lots of gangsterism as well as gunshots every night” in the neighborhood...... https://apnews.com/article/johannesburg-troops-crime-crackdown-president-d92dd6dc8eea76bdf1abd878200379f9

Marx21.it

@marx21news · Post #9208 · 14.11.2025 г., 14:45

Un nuovo capitolo strategico tra Việt Nam e Sudafrica La visita di Stato del Presidente sudafricano Cyril Ramaphosa a Hà Nội (23-24 ottobre) segna una svolta storica nelle relazioni tra i due Paesi. Dopo decenni di cooperazione politica ed economica, il Việt Nam e il Sudafrica si preparano a elevare il loro rapporto a Partenariato Strategico entro il 2025, fondato su fiducia politica, sviluppo sostenibile e convergenza multilaterale. Le radici del legame risalgono alla solidarietà anticoloniale e al movimento afro-asiatico, ma oggi la partnership guarda al futuro: energie rinnovabili, digitalizzazione, infrastrutture, finanza verde e libero scambio con la SACU. Il Việt Nam si conferma ponte tra Asia e Africa, mentre il Sudafrica punta a rafforzare il proprio ruolo di hub continentale. Entrambi i Paesi condividono una visione del Sud Globale unito, promotore di un ordine internazionale più equo, basato su cooperazione, legalità e rispetto reciproco. La dichiarazione congiunta del 24 ottobre non chiude un ciclo, ma ne apre uno nuovo: quello di una cooperazione Sud-Sud più matura, fondata su principi, pragmatismo e ambizioni globali comuni. #Vietnam#SouthAfrica#Ramaphosa#CooperazioneSudSud#Diplomazia#Geopolitica#ASEAN#Africa#PartenariatoStrategico#GiulioChinappi https://www.marx21.it/internazionale/un-nuovo-capitolo-strategico-nella-cooperazione-tra-vietnam-e-sudafrica/