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

Пребарај: #helenacrevar

当前筛选 #helenacrevar清除筛选
bjjfanaticsinstructionals

@bjjfanaticsinstructionals · Post #1807 · 24.04.2025 г., 17:27

🔥NEW RELEASE🔥 😁Leg Locks Finishes By Helena Crevar😁 ➡️Unlock the secrets to finishing leg locks with Leg Locks Finishes, the highly anticipated Brazilian Jiu-Jitsu instructional by the rapidly rising star of the sport, Helena Crevar. ➡️Her impeccable technique, precise attention to detail, and aggressive competition record make her the perfect guide to take your leg lock game to the next level. ➡️In this comprehensive instructional, Helena breaks down her favorite leg lock finishes, focusing on efficient setups, seamless transitions, and perfecting the art of submission under pressure. $197😍$14.99😍 ❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️ 📱Payment: 📱📱📱 💰Submeta FOR FREE 🌈UFC Picks 👑MasterClass ✈️@bjjfanaticsinstructionals #HelenaCrevar#WomenBJJ#Leglocks#NoGi#Danaher 💁‍♀️Buy 💁‍♀️

bjjfanaticsinstructionals

@bjjfanaticsinstructionals · Post #1806 · 24.04.2025 г., 17:25

🔥NEW RELEASE🔥 😁Leg Lock Entries By Helena Crevar😁 ➡️Unlock the power of leg locks with Helena Crevar's BJJ Instructional on Leg Lock Entries. As one of the fastest rising stars in Brazilian Jiu-Jitsu, Helena has been turning heads worldwide with her technical precision and mastery of the game ➡️Trained under the legendary John Danaher, Helena’s leg lock game is among the best in the world. This instructional video provides you with clear, step-by-step guidance on entries that will elevate your leg lock game to new heights. ➡️This is your opportunity to learn from one of the brightest talents in BJJ and take your leg lock entries from basic to lethal. $197😍$14.99😍 ❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️ 📱Payment: 📱📱📱 💰Submeta FOR FREE 🌈UFC Picks 👑MasterClass ✈️@bjjfanaticsinstructionals #HelenaCrevar#WomenBJJ#Leglocks#NoGi#Danaher 💁‍♀️Buy 💁‍♀️