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

Резултати

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

Пребарај: #bbclearningenglish

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

@english_bbc_learning · Post #3811 · 20.12.2025 г., 15:34

🎄 Do you know how to respond when an English speaker wishes you a merry Christmas?’ Try this quiz - we’ll tell you the answer later! Are there any other ways you could respond? 🤶 ⁣ ⁣ [Image: Getty]⁣ ⁣ EXTRA: This festive season, we're sharing some of our own stories about Christmas and New Year. Link in bio.⁣ ⁣ #learnenglish#english#bbclearningenglish⁣

BBC Learning English

@english_bbc_learning · Post #3761 · 16.11.2025 г., 08:45

😊 The next time you're feeling 'happy', try using one of these synonyms instead and boost your vocabulary! ✍️ See if you can use one of them in the comments. ⁣ ⁣⁣ Note: not all the words are perfect synonyms. Pay attention to the context and grammar. ⁣⁣⁣ ⁣⁣ MORE: Is happiness the key to success? 🔎 Find out in this episode of 6 Minute English. Click on the link in our bio.⁣ ⁣⁣ #englishlesson#englishwords#englishvocabulary#english#bbclearningenglish

BBC Learning English

@english_bbc_learning · Post #3759 · 10.11.2025 г., 09:49

🍱🥘🍲 The next time you eat something delicious, try using one of these synonyms instead and boost your vocabulary! ✍️ See if you can use one of them in the comments.⁣ ⁣⁣ Note: not all the words are perfect synonyms. Pay attention to the context and grammar. ⁣⁣⁣ ⁣⁣ 🎧 MORE: Click on the link in our bio to listen to a 6 Minute English box set on the topic of food.⁣ ⁣ #englishlesson#englishwords#englishvocabulary#english#bbclearningenglish

BBC Learning English

@english_bbc_learning · Post #3747 · 03.11.2025 г., 20:52

🚀 Take your English vocabulary to the next level by learning these alternatives to ‘less than’! Can you use one in a sentence - and do you know any more? ⁣ ⁣ 👀 Note: these words may not be exact synonyms - pay attention to the context.⁣ ⁣⁣ #englishlesson#englishwords#englishvocabulary#english#bbclearningenglish#englishteacher#lessthan

BBC Learning English

@english_bbc_learning · Post #3722 · 13.10.2025 г., 18:23

🤢😔 Everybody gets sick from time to time… so we made a vocabulary table with useful sickness-related English for you to learn, use, and share with a friend! 😄⁣ ⁣ Do you know any more English vocabulary related to illness? 👇 ⁣ #englishvocabulary#learnenglish#englishphrases#britishenglish#EFL#ESL#ELT#vocab#bbclearningenglish⁣

BBC Learning English

@english_bbc_learning · Post #3690 · 19.09.2025 г., 08:45

😱 Lots of animal species are at risk of extinction. 🐘🦁🦒Can you choose the correct word to fill the gap? We’ll tell you the correct answer later! (Image: Getty)⁣ ⁣ #environment#extinction#extinct#earth#animals#learnenglish#bbclearningenglish#vocab#englishquiz ⁣

BBC Learning English

@english_bbc_learning · Post #3809 · 15.12.2025 г., 05:11

Here are 5 linkers that you can add to your conversation to make it flow better and sound more fluent! 1) To be honest – I’m going to give my opinion (even if it’s insulting!) 2) Actually – to correct information or say something surprising 3) Mind you – I’ve just thought of something that contrasts what I was saying 4) By the way – I’m going to introduce a new topic I’ve just remembered 5) Anyway – I’m going to finish the conversation or change topic now Add them to your conversations to help them flow! Which one is your favourite? #learnenglish#speakenglish#vocabulary#bbclearningenglish#britishenglish#formalenglish#linkers#naturalenglish#nativespeakerenglish#conversationskills#ncoversationalenglish

BBC Learning English

@english_bbc_learning · Post #3689 · 07.09.2025 г., 03:15

❓❓❓Do you know how to respond when an English speaker asks ‘Is the post office open today?’ 🏣Try this quiz - we’ll tell you the answer later! Are there any other ways you could respond?👇👇👇⁣ ⁣ [Image: Getty]⁣ ⁣ #learnenglish#socialenglish#correctresponse#englishquiz#english#englishvocabulary#learnenglish#englishphrases#contraction#question#shortanswer#britishenglish#EFL#ESL#ELT#vocab#bbclearningenglish⁣