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

Резултати

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

Пребарај: #amitytashkent

当前筛选 #amitytashkent清除筛选
Amity University Tashkent

@amityuniversitytashkent · Post #5138 · 06.11.2025 г., 15:10

#photoreport 😃✨Graduation Vibes at Amity University Tashkent! ✨🎓 On November 6, we proudly celebrated the Graduation Ceremony of the Class of 2025 — a day full of joy, pride, and unforgettable memories! 😍 🎶The event kicked off with the National Anthem of Uzbekistan, setting a proud tone for the celebration. Inspiring speeches followed from Mr. Rustam Karimjonov, Deputy Minister of Digital Technologies of Uzbekistan, and Mr. Amol Chauhan, Senior Vice President of Amity University. 👏 They applauded the dedication and achievements of our graduates and encouraged them to shape the future with passion, creativity, and purpose. 💫 #AmityTashkent#Graduation2025#ProudMoment#AmityFamily 🇺🇿O'zbek tilida 😜Telegram😂Facebook😀Instagram😅Youtube😃Linkedin

Amity University Tashkent

@amityuniversitytashkent · Post #5071 · 25.10.2025 г., 04:21

😀 Heartfelt Congratulations to Dr. Ashok K. Chauhan 🌟 Today, the team of Amity University Tashkent proudly extends its warmest congratulations to Dr. Ashok K. Chauhan, the visionary Founder President of Amity Education Group. Your dedication, wisdom, and lifelong mission to transform education have built a legacy that continues to inspire millions of students across the world. Under your exceptional leadership, Amity has become a global symbol of knowledge, innovation, and human values. Your belief that “Each student must be a success story” resonates deeply with our purpose here in Tashkent and guides us to nurture future leaders with passion and integrity. 💫 We wish you endless energy, good health, and continued success in your noble journey of shaping minds and empowering generations. With deepest respect and admiration, Team of Amity University Tashkent 🇺🇿 #AmityUniversity#AmityTashkent#DrAshokKChauhan#FounderPresident#AmityEducationGroup#GlobalEducation#Leadership#SuccessStory#AmitySpirit#ProudToBeAmity 😜Telegram😂Facebook😀Instagram😅Youtube😃Linkedin