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

Резултати

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

Пребарај: #cryptogaming

当前筛选 #cryptogaming清除筛选
Win Path Crypto

@WinPath · Post #7954 · 17.04.2026 г., 19:53

🔥Daily Case Task in WeMine! 📆Date: April 17, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7951 · 15.04.2026 г., 19:06

🔥Daily Case Task in WeMine! 📆Date: April 15, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7948 · 14.04.2026 г., 18:43

🔥Daily Case Task in WeMine! 📆Date: April 14, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7945 · 13.04.2026 г., 19:06

🔥Daily Case Task in WeMine! 📆Date: April 13, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7942 · 12.04.2026 г., 18:40

🔥Daily Case Task in WeMine! 📆Date: April 12, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7939 · 11.04.2026 г., 17:43

🔥Daily Case Task in WeMine! 📆Date: April 11, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7936 · 10.04.2026 г., 18:44

🔥Daily Case Task in WeMine! 📆Date: April 10, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7932 · 09.04.2026 г., 17:58

🔥Daily Case Task in WeMine! 📆Date: April 09, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7929 · 08.04.2026 г., 17:34

🔥Daily Case Task in WeMine! 📆Date: April 08, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7926 · 07.04.2026 г., 19:49

🔥Daily Case Task in WeMine! 📆Date: April 07, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7923 · 06.04.2026 г., 18:37

🔥Daily Case Task in WeMine! 📆Date: April 06, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

Win Path Crypto

@WinPath · Post #7920 · 05.04.2026 г., 18:25

🔥Daily Case Task in WeMine! 📆Date: April 05, 2026 ⏫ Be quick to grab the top rewards! 👉Join the WeMine bot 🔔Channel | 💬Chat – Join us! ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️#WeMine#CryptoGaming

123•••10•••20•••2627
ПретходнаСтраница 1 од 27Следна