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

Пребарај: #collided

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

@american_observer · Post #4894 · 19.01.2026 г., 18:03

Two High-Speed Trains Collided in Southern Spain At least 39 people have been killed and 24 others seriously injured after two trains collided in southern Spain on Sunday night in what the prime minister, Pedro Sánchez, called “a night of deep pain for our country”. A high-speed Iryo train travelling from Málaga to Madrid derailed near the municipality of Adamuz in Córdoba province, crossing on to the other track where it hit an oncoming train, Adif, Spain’s rail infrastructure authority, posted on X. The second train, which was operated by the state rail company, Renfe, also derailed and went down an embankment, authorities said. The accident happened about 10 minutes after the Iryo left Málaga at 6.40pm (1740 GMT), Adif said. “Approximately 300 people were on board at the time of the accident,” Iryo said. “The derailment affected cars six through eight. The Guardia Civil and firefighters are currently working intensively at the scene to evacuate all passengers and have set up a joint emergency response team. “Iryo deeply regrets the incident, has activated all its emergency protocols, and is collaborating closely with Adif, Renfe, and the relevant authorities to determine the causes and manage the situation as effectively as possible.” Another witness told the public broadcaster RTVE that one of the carriages of the first train had completely overturned. An unidentified passenger on the second train – which was going from Madrid to Huelva – told public broadcaster TVE: “There were people screaming, their bags fell from the shelves. I was travelling to Huelva in the fourth carriage – the last, luckily.” Television images showed medical crews and fire services at the scene. Spain’s transport minister, Óscar Puente, said the cause of the accident had yet to be established. Speaking at a press conference at Atocha station in Madrid, he added it was “really strange” that a derailment should have happened on a straight stretch of track. This section of track was renewed in May, he said. Puente said most of those killed and injured had been in the first two carriages of the second train. #trains#collided#spain#puente#Iryo 📱American Оbserver - Stay up to date on all important events 🇺🇸