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

Пребарај: #empower

当前筛选 #empower清除筛选
DWF Labs Broadcast

@Dwflabs · Post #125 · 30.12.2022 г., 03:34

We're receiving a stream of good news before the year-end 👀💥 Conflux Network is expanding into Hong Kong and working to accelerate #web3 integration into the traditional internet business and economies 🫡 ▫️Dr. Ming Wu, co-founder of Conflux Network, was invited to Hong Kong to speak with various government and private organizations about the digital economy, innovation and technology, and has reached an initial strategic cooperation intention. ▫️Conflux is currently registering related entities for the entry into Hong Kong, solidifying its role as foundational infrastructure for Web3. ▫️This follows October’s announcement of the “Policy Declaration on the Development of Hong Kong Virtual Assets” which has paved the way for a more hospitable blockchain environment in Hong Kong. We're privileged to be able to support your continuous development and hard work to further #empower and grow tech innovation as well as the larger #Web3 adoption. Read more here.

Venture Village Wall 🦄

@venturevillagewall · Post #3617 · 21.12.2024 г., 10:22

Skynet Raises $1.20M Skynet has successfully raised $1.20 million to enhance its platform, which aims to empower AI agents to connect seamlessly with global resources. For more information, visit Skynet. #Skynet#AI#Funding#Resources#Tech#Innovation#Investment#Global#Agents#Platform#Development#Seamless#Connect#Empower#Industry#Tools

Venture Village Wall 🦄

@venturevillagewall · Post #3401 · 18.12.2024 г., 12:10

Askable Raises $14.04M Askable has successfully raised $14.04 million as of December 11, 2024, offering a powerful research platform that connects users with top researchers and ideal participants for quick insights and faster decision-making. More details at Askable. #Funding#Research#Insights#Platform#Participants#Decisions#Teams#Technology#Fast#Access#Empower#Global#Data#Analytics#Investments#Startups#Business#Growth#Innovation#Online