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

Резултати

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

Пребарај: #englishclass

当前筛选 #englishclass清除筛选
BBC Learning English

@english_bbc_learning · Post #3748 · 05.11.2025 г., 18:01

🤔 What phrases do you know with 🐶 ‘dog’? 🤩 We’re here to help you learn 7 phrases so you can feel like ‘a top dog’! Scroll through the images – and ✍️ write some sample sentences of your own!⁣ ⁣ 🥹 Researchers from Japan say dogs could cry happy tears when they see their owners. 😊 Learn more about this story by clicking on the link in our bio! ⁣ ⁣ Images: Getty⁣ ⁣ #learnenglish#idiom#vocabulary#englishclass#IELTS

BBC Learning English

@english_bbc_learning · Post #3810 · 17.12.2025 г., 07:53

Are you a helpful person? 💪😊 Help us out by writing the missing word in this expression which means ‘If a lot of people help, a task can be completed quickly and easily’. ⁣ ⁣ Are you happy to help when you’re needed? 👇👇👇⁣ ⁣ MORE: Click the link in our bio to learn another expression with 'hand' that you can use in similar situations! 👋👋👋⁣ ⁣ Image: Getty⁣ ⁣ #learnenglish#vocabulary#englishclass#phrases#expressions#idiom#learnenglish

BBC Learning English

@english_bbc_learning · Post #3804 · 14.12.2025 г., 07:15

Do you know someone who always thinks that everyone else has a better life than them?! 🙄😅 Scroll through the images to find out how to use ‘the grass is always greener on the other side’ 🌱, and don’t forget to answer the questions on the last slide! ⁣ ⁣ EXTRA: Could walking 7,000 steps a day could improve your mental health? 🚶 Click the link in our bio to find out and learn some useful vocabulary in the process! 📰💚⁣ ⁣ Image: Getty⁣ ⁣ #vocabulary#learnenglish#englishlanguage#expression#idiom#proverb#englishclass#speakenglish

BBC Learning English

@english_bbc_learning · Post #3776 · 29.11.2025 г., 10:17

You know when somebody just WON’T change their ways? 😠 We’ve got an English expression for that! ✅ ⁣ ⁣ Scroll through the images to find out how to use ‘You can’t teach an old dog new tricks.’ ❌🐶 ⁣ ⁣ Can you use it in a sentence – and do you have a similar expression in your language? 👇👇👇⁣ ⁣ MORE: If you'd like to learn some more animal idioms, like 'rabbit on 🐰' or 'as sick as a parrot 🦜', click the link in our bio! ⁣ ⁣ Image: Getty⁣ ⁣ #trick#proverb#learnenglish#vocabulary#learnenglish#englishlanguage#expression#idiom#englishclass#speakenglish ⁣

BBC Learning English

@english_bbc_learning · Post #3821 · 23.12.2025 г., 13:20

What you do is more important than what you say, right? 👍 Can you complete this English expression that means exactly that? Write your answer in the comments and don’t forget to give this post a like! ⁣ ⁣ Do you have a similar expression in your language? 👇👇👇⁣ ⁣ Want to learn more English expressions and idioms? Click the link in our bio to listen to our podcast The English We Speak!⁣ ⁣ Image: Getty⁣ ⁣ #learnenglish#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang ⁣

BBC Learning English

@english_bbc_learning · Post #3720 · 10.10.2025 г., 15:34

😃Even if nobody in your family is called Bob, you can still use this informal English expression to say that a task is really simple and easy! Write your answer in the comments and be sure to like this post! Do you have a similar expression in your language? 👇👇👇⁣ ⁣ 🤩 MORE: Learn about the stories behind our names with this episode of ⏱️ 6 Minute English. Click the link in our bio NOW!⁣ ⁣ #idioms#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang ⁣

BBC Learning English

@english_bbc_learning · Post #3842 · 31.12.2025 г., 16:03

It’s almost New Year – and we’ve got a great expression you can use to say that ‘things will be different from now on!’ 🎉🥳 Choose the correct word to fill the gap – we’ll tell you the answer later! ⁣ ⁣ MORE: Click the link in our bio to see what our presenter's hopes, plans and dreams for 2025 were! 😄⁣ ⁣ Image: Getty⁣ ⁣ #learnenglish#newyear#happynewyear#freshstart#newbeginning#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang ⁣

BBC Learning English

@english_bbc_learning · Post #3724 · 17.10.2025 г., 12:23

🤩 Even if you don’t eat meat, you can still use this expression to say that you’re super-hungry! 😁 Write your answer in the comments and like and share this post! Do you have a similar expression in your language? 👇👇🤩⁣ ⁣ MORE: ⁉️Are you angry when you're hungry? There's an English expression for that! 😲 Click the link in our bio to find out what it is with ⏱️ 6 Minute English! ⁣ ⁣ Images: Getty⁣ #learnenglish#hungry#starving#horse#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang ⁣

BBC Learning English

@english_bbc_learning · Post #3658 · 15.07.2025 г., 18:29

🤔 Did something bad happen to you when you weren’t expecting it? You’re not going to put yourself in that situation again, are you? 😄 Learn this useful English expression that summarises this life lesson. Give this post a like, and ✍️ put your answer in the comments! Do you have a similar expression in your language?⁣ ⁣ 🤩 Click on the link in our bio to learn some modern idioms!⁣ ⁣ Images: Getty⁣ ⁣ #learnenglish#advice#idioms#esl#efl#vocabulary#englishclass#phrases#expressions#oncebitten#britishenglish#lifelesson#inspiration#slang