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

Резултати

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

Пребарај: #spin

当前筛选 #spin清除筛选
🏆 Premium, NFT, Tokens

@giiveaways · Post #3191 · 24.09.2024 г., 19:14

🪙SPIN & GET REAL CRYPTO A new feature is live: Giveaways by MemeFi!💥 😵 Prize pool starts at $1,000,000! How to win? ⭐️Spin the wheel 🔷 Hit the Ether icons 💯 Fill the Ether bar for a ticket to win $ETH! The event kicks off today with a $25,000 prize pool. Each day brings new giveaways! 🥇 🔔Subscribe👉Join MemeFi ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️ #memefi#spin#crypto

🏆 Premium, NFT, Tokens

@Giiveaways · Post #1993 · 06.06.2024 г., 20:49

📣 Catizens! We are about to welcome the next update, includes: Still worried about not being able to automatically buy the highest-grade airdrop cats? 📦 · The auto-buy function is coming soon! #Free your hands! 🚀 · At the same time, the offline #rewards have also been greatly advanced! This will make it easier for players to level up their cats, make #Catizen a real idle casual game! 😻 · Catizen has also adjusted the play experience of #SPIN(Increased randomness and reduced difficulty), don’t forget to try it again! https:://t.me/catizenbot/👈 #crypto#ton#game

Journey to Fluency

@fluencyinenglish · Post #7911 · 21.02.2026 г., 06:08

Spin (verb)/(noun) Verb: to present information in a favorable or strategic way Noun: a biased or strategic way of presenting information Example (verb): The government tried to spin the economic data as a success. دولت تلاش کرد داده‌های اقتصادی را به‌گونه‌ای ارائه کند که موفقیت‌آمیز به نظر برسد. Example (noun): The press secretary put a positive spin on the policy failure. سخنگوی مطبوعاتی به شکست سیاست، تفسیر مثبتی داد. Put a spin on : present something strategically She put a positive spin on the election results. او نتایج انتخابات را به شکل مثبتی تفسیر کرد. Spin doctor : political advisor who manages public perception The spin doctor tried to downplay the scandal. مشاور سیاسی سعی کرد رسوایی را کم‌اهمیت جلوه دهد. #idioms #discourseanalysis #criticalthinking #spin #framing #ielts#cae#fce