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

Резултати

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

Пребарај: #uxlinkfam

当前筛选 #uxlinkfam清除筛选
UXLINK

@uxlink_community · Post #438 · 17.04.2025 г., 23:35

🌍 UXLINK FujiCard KYC testing is kicking off in multiple countries! We’re currently running KYC process trials with amazing #UXLINKfam volunteers in Japan, Korea, Singapore, Indonesia, Vietnam, Nigeria, Pakistan, Bangladesh, South Africa, and across the Middle East. 🙌 Your enthusiasm and support have been incredible—shoutout to everyone helping our product and engineering teams fine-tune this across the globe! This progress brings us one step closer to launching our #UXLINK#PayFi system: FujiPay/FujiCard—on track for the first half of this year! ⏰💳 But here’s the vision: FujiCard isn’t just a card—it’s the most socialized virtual crypto card ever built. 🌟 We’re bridging the physical and digital worlds, making payments as seamless as chatting with friends—because finance should be inclusive, intuitive, and interconnected. 🌐💫 Our goal? To become the WeChat Pay/Line Pay of the blockchain world—a gateway where everyday users can spend, earn, and connect globally, all while leveraging the power of decentralized finance. 🌍💰 Stay tuned as we build a future where finance is social, borderless, and ready for everyone. The revolution starts with you. Let’s make every transaction a step toward a more connected world! 🚀✨ #Web3#payment