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

Резултати

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

Пребарај: #vocabulary

当前筛选 #vocabulary清除筛选
English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60783 · 16.05.2026 г., 14:43

#Vocabulary 🕸Dormant 🦦 (of an animal) having normal physical functions suspended or slowed down for a period of time; in or as if in a deep sleep 🫧 Ex:- During the winter months, the bears will often go dormant and hibernate. 🌨Basic Synonyms 🌓 asleep 🌓 slumbering 🌓 inactive 🌟Advanced Synonyms ✨ comatose ✨ supine ✨ lethargic ✨ torpid ✨ aestivating 🌔Antonyms 🍀 awake 🍀 wakeful

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60772 · 10.05.2026 г., 14:57

#Vocabulary 🎶Repertory2⃣ 🎼a collection, especially of music or information 🎻 Ex:- This year, the Boston Philharmonic has expanded its repertory to include compositions from Mexico. 🎸Basic Synonyms 🪉 collection

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60771 · 10.05.2026 г., 14:57

#Vocabulary 🎨Repertory1⃣ 🎭 the performance of various plays, operas, or ballets by a company at regular short intervals 🫟 Ex:- Martin was overjoyed when he learned his audition was good enough to get him accepted at the New York Repertory for Young Composers. ❄️Basic Synonyms 🫧 theater 🫧 troupe 🫧 school

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60762 · 06.05.2026 г., 20:12

#Vocabulary 📜 Screed 📝a long speech or piece of writing, typically one regarded as tedious ✍Example:- When they lost the match, the team coach launched into an almost incoherent screed on all the areas the team had to improve in. 📒Basic Synonyms 🖌 rant 📔Advanced Synonyms 🖍 harangue

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60761 · 06.05.2026 г., 20:12

#Vocabulary 🥢Palatable 🍽(of food or drink) pleasant to taste; has acceptable taste 🍴Example:- Tonight, a surprisingly palatable spread will be laid out on the table. Don't be shy — come. 🧉Basic Synonyms 🥤 tasty 🥤 eatable 🍹Advanced Synonyms 🧋 appetizing 🧋 edible 🧋 savoury 🧋 delectable 🧋 luscious 🧋 flavourful 🧃Antonyms 🫗 distasteful 🫗 unsavoury

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60672 · 26.03.2026 г., 20:48

#Vocabulary ❄️Turnover 🕸The amount of money taken in by a business in a particular period 🫧 Ex:- The company's annual turnover exceeded expectations.

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60617 · 04.02.2026 г., 18:45

#Vocabulary 🌺Diffident. ●Lacking or marked by a lack of self-confidence; shy and timid, distrustful of one's own powers. ●He was diffident about his own success. ●Because she was only a first-year student, she was diffident when offering a comment on the professor's lecture.

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #60616 · 04.02.2026 г., 18:43

#Vocabulary 🌺Spurious /ˈspjʊəriəs/ 《adjective》 ●a spurious statement, argument etc is not based on facts or good thinking and is likely to be incorrect. ▪️He demolished the opposition’s spurious arguments.

Hashtags

123•••10•••20•••30•••3233
ПретходнаСтраница 1 од 33Следна