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

Резултати

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

Пребарај: #futuremindssummit

当前筛选 #futuremindssummit清除筛选
Opportunities with Zula

@opportunities_zula · Post #1859 · 16.04.2026 г., 18:48

Yes, you heard it right! The Future Minds Summit covers your airfare, meals, accommodation, and even your visa costs. Eligibility: Open to Worldwide Participants 📍 Bangkok, Thailand 🇹🇭 🗓 Event Dates: 16-19 July 2026 ⏳ Deadline: 16 June 2026 👉 Apply here: https://thegyn.org/fms-thailand/ (link in bio) #FutureMindsSummit #Thailand #CallForDelegates#YouthLeadership#FundedOpportunity FMST

Opportunities with Zula

@opportunities_zula · Post #1845 · 15.04.2026 г., 10:44

📣 Call For Worldwide Applications! The Future Minds Summit Thailand 🇹🇭 2026 invites motivated youth from across the world to take part in a global leadership and Intellectual dialogue on Sustainable Development Goals in Bangkok, Thailand 🎓 Theme: Exploring Sustainability through Innovative Minds 🌍 Open to Worldwide Participants Scholarship Covers: ✈️ Airfare 🗄️ Visa Fees (if any) 🏨 Accommodation 🍽 Meals & Tea Breaks 📄 Visa support & Certification 🎙️ Speaking Opportunity at the Forum 🤝 All Social Activities & Cultural Fest 🗓 Event Dates: 16-19 July 2026 ⏳ Deadline: 16 June 2026 👉 Apply here: https://thegyn.org/fms-thailand/ #FutureMindsSummit #Thailand #CallForDelegates#YouthLeadership#FundedOpportunity

Opportunities with Zula

@opportunities_zula · Post #1857 · 16.04.2026 г., 15:42

Bangkok is Calling Future Leaders! Visit: https://tinyurl.com/fms-thailand2026 Applications are now open for the GYN FutureMinds Summit 2026 in vibrant Bangkok, Thailand Whether you're a student, graduate, or professional (ages 16–45), this is your chance to connect, learn, and lead on a global stage. No specific background required — just passion and vision! What’s Covered? Airfare Accommodation Meals & Tea Breaks Visa Support & Fees (if applicable) Speaking Opportunity Cultural Fest & Social Activities Certification Join a diverse network of changemakers, gain international exposure, and make your voice heard where it matters. Tag someone who shouldn’t miss this opportunity! #FutureMindsSummit#FullyFunded#YouthLeaders#GlobalOpportunities#Bangkok2026#Changemakers#ApplyNow