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

Пребарај: #hodlers

当前筛选 #hodlers清除筛选
Morningstar Ventures (News & Announcements)

@morningstar_ventures · Post #71 · 24.03.2022 г., 16:14

The EGLD Community Platform Goes Live 💫 We have been Elrond community members (and #hodlers) for a long time already and deeply care about the Elrond ecosystem. Today we are announcing the launch of a product we have been working on behind the scenes for quite some time and will hopefully add a lot of value to the Elrond ecosystem. Meet the "EGLD Community" - a social platform to discover, learn and talk about all-things Elrond! Discover more and sign up here: ➡️https://bit.ly/36ILzfM

Hashtags

DWF Labs Broadcast

@Dwflabs · Post #185 · 28.01.2023 г., 05:29

BIT x DWF Labs Crypto Snapshot [27 Jan] 📰 Highlights: 🔸 Diamond Hands Rule The Charts As #Bitcoin#HODLers Continue To Hold Despite Gains 🔸 The Open Network Move Towards Utility By Suspending Inactive Wallets 🔸 CRV Liquidity Providers Hungry For More Options Full read here.

SIGNAL

@finsignal · Post #3408 · 24.07.2024 г., 11:08

🥸 Above is a 10-year chart of significant #altcoins and the number of non-empty wallets (#hodlers) in the corresponding networks: #Litecoin: 8.08M wallets #Dogecoin: 6.69M wallets #XRP Ledger: 5.24M Wallets #Cardano: 4.48M Wallets #Shiba Inu: 1.39M wallets #Chainlink: 722K wallets