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 слични објави

Пребарај: #unday

当前筛选 #unday清除筛选
Statistica Moldovei

@statisticamd · Post #875 · 24.10.2024 г., 12:55

🌐 Astăzi, 24 octombrie, este celebrată Ziua Națiunilor Unite 🇺🇳. 🤝 Biroul Național de Statistică adresează sincere felicitări organizațiilor ONU Moldova și mulțumiri pentru că ne sunt alături și ne oferă suport continuu în vederea consolidării capacităților sistemului statistic național și modernizării producției și diseminării datelor statistice de calitate, în corespundere cu standardele internaționale. #ZiuaONU#UNDay

🇰🇬🇺🇳 Кыргыз Республикасы эл аралык коомчулук менен катар БУУнун күнүн белгиледи 🇰🇬🇺🇳 Кыргызская Республика присоединяется к мировому сообществу в праздновании Дня Организации Объединенных Наций 🇰🇬🇺🇳 The Kyrgyz Republic joins the international community in celebrating United Nations Day #UNDay#UN#UnitedNations#ООН 🔗 Толугураак / Подробнее: mfa.gov.kg LinkedIn | Instagram | X (Twitter) | Facebook | YouTube

Yoshlar Markazi | Ziyo Forum

@YouthCenterZiyo · Post #1050 · 29.10.2025 г., 09:32

☀️ “Ziyo Forum” yoshlar markazida BMT kuni munosabati bilan “Youth United for the UN Day: Empowering Sustainable Future” sessiyasi bo‘lib o‘tdi! 🇺🇳27-oktabr kuni “Ziyo Forum” yoshlar markazida yoshlar uchun ilhomlantiruvchi sessiya tashkil etildi. Tadbir davomida Alisher Asrorov— UNODC Youth Network Leader in Uzbekistan, Webster Universitetining Career & Business Development menejeri va sobiq BMT Yoshlar Kengashi raisi — BMTning O‘zbekistondagi faoliyati, Barqaror Rivojlanish Maqsadlari (SDGs) hamda yoshlarning global tashabbuslardagi o‘rni haqida o‘z tajribasi asosida so‘zlab berdi. 📌Ishtirokchilar ochiq muloqotda faol qatnashib, “Kahoot” viktorinasida o‘z bilimlarini sinovdan o‘tkazishdi. Tadbir yakunida eng faol yoshlarga maxsus sovg‘alar topshirildi va umumiy suratga tushildi. 🌍Sessiya iliq va ilhomlantiruvchi muhitda o‘tib, yoshlarni global fikrlash va barqaror kelajak sari ilhomlantirdi. 📸 Barcha suratlarni quyidagi havola orqali ko‘rishingiz mumkin: 👉https://disk.yandex.ru/d/1A8GU1Uc6bujhg ☀️ “Youth United for the UN Day: Empowering Sustainable Future” session was successfully held at Ziyo Forum Youth Center! 🇺🇳On October 27, a special and inspiring session took place at the Ziyo Forum Youth Center. Alisher Asrorov— UNODC Youth Network Leader in Uzbekistan, Career & Business Development Manager at Webster University, and former Chair of the UN Youth Advisory Board — shared his insights on the UN’s role in Uzbekistan, the Sustainable Development Goals (SDGs), and the importance of youth participation in global initiatives. 📌Participants actively engaged in open discussions and tested their knowledge through the interactive Kahoot quiz. The most active attendees received special gifts, and the event concluded with a group photo. 🌍The session took place in a warm and inspiring atmosphere, motivating young people to think globally and contribute to a sustainable future. 📸 Check out all the event photos at the link below: 👉https://disk.yandex.ru/d/1A8GU1Uc6bujhg #ZiyoForum#UNDay#YouthEmpowerment#SustainableFuture#UNUzbekistan#SDGs#YouthCenter