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

Пребарај: #premiumvip

当前筛选 #premiumvip清除筛选
Fx Signals_Gold #XAUUSD(GOLD)💰

@FxSignals_Gold · Post #10767 · 29.04.2026 г., 05:25

It's Mid-week! We hope you're not relenting in your pursuit of success? Keep grinding and keep your eyes laser focused on your goals. As you continue in the week, avoid distractions and only spend time doing things that add value to you. Brace up, the week hasn't ended yet! For Question, Information,Feedback ... Kindly Contact ☎️T.me/FrxMaster_Gold #PremiumVIP💯 #PropFirmChallenge&Verification✅ #FUNDEDAccountManagement👨🏻‍💻

Fx Signals_Gold #XAUUSD(GOLD)💰

@FxSignals_Gold · Post #10745 · 24.04.2026 г., 11:33

JUST IN FOR VERIFICATION CHALLENGE ‼️ • Prop Firm - FTMO • Challenge level - Phase 2 • Starting Balance - ($10,000) • Current Balance - ($10,506.46) • Target Profit - ($500 Growth) • Profit - ($513.35) • Floating Profits - ($0) • Drawdown 3.47% • Trading Period - (3 Days) Interested Investors Should Share with us; Platform: Account ID: Password: Server Name: Sign In Your Account Today For NEXT WEEK Trading. Take a leap of faith and see your account grow consistently with us...Trust in our expertise. You surely won't be disappointed 👌 For Question, Information,Feedback ... Kindly Contact ☎️T.me/FrxMaster_Gold #PremiumVIP💯 #PropFirmChallenge&Verification✅ #FUNDEDAccountManagement👨🏻‍💻

Fx Signals_Gold #XAUUSD(GOLD)💰

@FxSignals_Gold · Post #10707 · 16.04.2026 г., 08:21

JUST IN FOR VERIFICATION CHALLENGE ‼️ • Prop Firm - FTMO • Challenge level - Phase 1 • Starting Balance - ($10,000) • Current Balance - ($10,594.64) • Target Profit - ($1k Growth) • Profit - ($594.64) • Floating Profits - ($78.7) • Drawdown 0.47% • Trading Period - (2 Days) Interested Investors Should Share with us; Platform: Account ID: Password: Server Name: Sign In Your Account Today For THIS WEEK Trading. Take a leap of faith and see your account grow consistently with us...Trust in our expertise. You surely won't be disappointed 👌 For Question, Information,Feedback ... Kindly Contact ☎️T.me/FrxMaster_Gold #PremiumVIP💯 #PropFirmChallenge&Verification✅ #FUNDEDAccountManagement👨🏻‍💻