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

Резултати

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

Пребарај: #maine

当前筛选 #maine清除筛选
White House Watch

@Whitehousewatch · Post #17316 · 25.01.2026 г., 00:23

#Maine: La Governatrice del Maine Janet Mills (D) ha chiesto un incontro con Donald Trump per chiedergli la sospensione delle operazioni anti-immigrazione in Maine. Tali operazioni sono cominciate qualche giorno fa.

Hashtags

White House Watch

@WhiteHouseWatch · Post #17834 · 01.03.2026 г., 22:48

#Iran, #Maine: Ed è botta e risposta su X tra la senatrice Susan Collins (R-Maine), il suo potenziale sfidante democratico Graham Platner e il Senatore Ted Cruz (R-Texas). Collins ha detto che il Congresso dev'essere coinvolto "I nostri soldati altamente preparati sono nelle mie preghiere mentre svolgono la missione", una dichiarazione su cui Platner ha deciso di rispondere: "Posso rassicurarla che le sue preghiere non hanno salvato la vita dei miei amici quando sono morti nell'ultima guerra che lei ha appoggiato." A questo punto, nella diatriba si è unito Cruz: "I tuoi amici avevano anche loro tatuaggi della Germania Nazista?" Platner, infatti, sul petto ha un Totenkopf che si è procurato mentre era in congedo militare in Croazia nel 2007. "No, Ted" ha risposto Platner, "I miei amici sono morti e rimarranno per sempre Marine degli Stati Uniti, testa di cazzo."

Hashtags

White House Watch

@Whitehousewatch · Post #17448 · 10.02.2026 г., 15:12

#Maine, #GOP: Susan Collins, senatrice repubblicana del Maine ha annunciato la volontà di ricandidarsi al Senato per un sesto mandato. Collins è uno dei volti moderati dei repubblicani ed è a capo della Commissione sugli Stanziamenti, quella che si occupa di scrivere e negoziare la legge di bilancio con i democratici. Il seggio del Maine è da molto tempo tra gli obiettivi dem e non è da meno anche quest'anno. I democratici hanno bisogno di sottrarre ai repubblicani 4 seggi per ottenere la maggioranza nell'aula e Collins è l'unica senatrice repubblicana a rappresentare un seggio vinto da Kamala Harris nel 2024.

Hashtags

Crypto M - Crypto News

@CryptoM · Post #64711 · 09.04.2026 г., 15:34

🚀 Maine Set to Implement Statewide Ban on Data Center Construction Until 2027 Maine is poised to become the first U.S. state to prohibit the construction of data centers statewide, following the approval of a legislative bill this week. According to Foresight News, the measure, which aims to halt data center development until November 2027, is expected to receive final approval in the coming days. The legislation also establishes a committee to propose a regulatory framework for data centers to prevent potential increases in energy prices or other issues for Maine residents. Despite bipartisan support for the bill, it has faced strong opposition from technology groups and businesses. Critics argue that even a temporary delay in construction could hinder the state's progress. #Maine#DataCenterBan#DataCenters#EnergyPrices#TechnologyOpposition#Legislation#BipartisanSupport#EnergyRegulation#ConstructionDelay