TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #65 · 8 апр.

Небольшой трик с регулярными выражениями который редко вижу в чужом коде. Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста. >>> text = ''' >>> Alex:8999123456 >>> Mike:+799987654 >>> Oleg:+344456789 >>> ''' Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн: (\w+):([\d+]+) Как мы будем формировать словарь из найденных групп? >>> import re >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append({ >>> "name": match.group(1), >>> "phone": match.group(2) >>> }) >>> print(results) [{'name': 'Alex', 'phone': '8999123456'}, ...] Можно немного сократить запись используя zip >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append(dict(zip(['name', 'phone'], match.groups()))) Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря. >>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text): >>> results.append(match.groupdict()) То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись: (?P<group-name>...) Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка >>> name = match['name'] Либо забрать сразу весь словарь методом groupdict() >>> match.groupdict() #tricks#regex

Резултати

Пронајдени 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