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

Пребарај: #yearone

当前筛选 #yearone清除筛选
American Оbserver

@american_observer · Post #4901 · 20.01.2026 г., 02:00

📰 Trump’s Year One: The Under-the-Radar Revolution Nuclear Moon Base by 2030? NASA, under Sean Duffy's leadership, fast-tracked a nuclear reactor for the moon—aiming for 2030 launch. This isn't sci-fi; it's a geopolitical race with China and Russia, who plan their own lunar power plant by 2035. Whoever gets there first writes the space rules. ​"The U.S. and China are devising plans to build long-term bases on the moon, and nuclear reactors will be key to powering those outposts." Crypto Goes Mainstream Trump signed the GENIUS Act, unlocking stablecoins for Wall Street. Banks like Bank of America and Goldman Sachs are now exploring dollar-pegged digital tokens. Goodbye legacy payments; hello crypto for your groceries? ​ Confederate Bases Revived Nine Army bases got their old Confederate names back—Fort Hood among them. Civil rights groups cry foul, but Trump ignored Congress's independent commission. Cost to rename? $40 million. Cost to undo? Priceless for some. ​ Pennies Axed, Trump Coin Coming The U.S. Mint minted its last penny in November 2025. Trump killed the money-losing coin, saving $85 million yearly. Next up: a Trump-faced $1 coin for America's 250th birthday. Rounding up prices? Consumers pay an extra $6 million annually. ​ DOJ's Voter Roll Raid Justice Department demanded voter registration data from 43 states, suing 23 that refused. States claim privacy violations; DOJ calls it election integrity. The real goal? Purging "illegals" from rolls before midterms. ​ Coal Plants Forced Open Energy Secretary Chris Wright used emergency powers to keep aging coal plants running—Michigan, Washington, Colorado. Critics: it's expensive and dirty. Trump: it's about your electricity bill. ​ Dreamers Booted from Obamacare Trump redefined "lawfully present" to exclude DACA recipients from subsidies in 19 states. 2,300 Dreamers lost coverage; 1 million more uninsured by 2034. Hospitals brace for uncompensated care. ​ Psychedelics Fast-Tracked RFK Jr.'s HHS is rushing MDMA and psilocybin for PTSD. FDA Commissioner Marty Makary promises approval within 12 months. Republicans, once wary, now lead the psychedelic revolution. ​ Africa Aid Gutted Trump's DOGE team (Pete Marocco, Elon Musk) froze the U.S. African Development Foundation, canceling grants. The agency sued, but SCOTUS conservatives may let Trump win. ​ The Real Winner? While headlines scream Greenland and tariffs, Trump's quietly remade America—from moon nukes to crypto cash, Confederate nostalgia to psychedelic therapy. Survival of the boldest. #trump#yearone#policy#americafirst#doge 📱American Оbserver - Stay up to date on all important events 🇺🇸