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

Пребарај: #mikeymusumeci

当前筛选 #mikeymusumeci清除筛选
bjjfanaticsinstructionals

@bjjfanaticsinstructionals · Post #1808 · 24.04.2025 г., 17:30

🔥NEW RELEASE🔥 😁Slicin' Calves By Mikey Musumeci😁 ➡️Mikey Musumeci, one of the most accomplished and detail-oriented American grapplers of all time, brings you a game-changing BJJ instructional that dives deep into one of the most lethal and versatile submissions in no-gi grappling: the Calf Slicer ➡️Whether you’re attacking the legs with a heel hook, straight footlock, or kneebar, Mikey shows you how to use the inevitable escape of your opponent to effortlessly transition into the calf slicer. ➡️With Mikey’s methodical approach and world-class attention to detail, you’ll gain the tools to dominate from bottom to top, turning every leg attack into a calf slicer opportunity. $197😍$14.99😍 ❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️ 📱Payment: 📱📱📱 💰Submeta FOR FREE 🌈UFC Picks 👑MasterClass ✈️@bjjfanaticsinstructionals #MikeyMusumeci#Leglocks#NoGi#IBJJF 💁‍♀️Buy 💁‍♀️

bjjfanaticsinstructionals

@bjjfanaticsinstructionals · Post #1775 · 02.03.2025 г., 00:17

🔥NEW RELEASE🔥 😁Fundamentals Of Guard Passing: Breaking Their Guard - Wall By Wall By Mikey Musumeci😁 ➡️Discover the Fundamentals of Guard Passing: Breaking Their Guard - Wall by Wall with BJJ legend Mikey Musumeci. As a multiple-time World Champion, ONE Championship star, and now UFC Fight Pass sensation ➡️Mikey brings his unmatched expertise to the world of guard passing, breaking down the essential foundations you need to elevate your no-gi game. ➡️In this groundbreaking first-ever instructional, Mikey Musumeci reveals the strategies and techniques that have made him one of the most dominant forces in the world of Brazilian Jiu-Jitsu $197😍$19.99😍 ❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️ 📱Payment: 📱📱📱 💰Submeta FOR FREE 🌈UFC Picks 👑MasterClass ✈️@bjjfanaticsinstructionals #MikeyMusumeci#OneFC#UFC#UFCFightPass 💁‍♀️Buy 💁‍♀️