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

Резултати

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

Пребарај: #hesterpeirce

当前筛选 #hesterpeirce清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3944 · 21.01.2025 г., 22:00

Trump Calls for Ross Ulbricht's Release Senator Rand Paul urges President Trump to free Ross Ulbricht, the founder of Silk Road. Meanwhile, Coinbase CEO Brian Armstrong states Trump is excited about a Strategic Bitcoin Reserve, aiming to be the first Bitcoin President. Additionally, Binance's CEO predicts a crypto all-time high in 2025 amid clearer U.S. regulation under Trump. Critical Metals Corp raises $500M for Bitcoin reserve strategy as they accept BTC as treasury asset—first Nasdaq company in critical minerals sector to do so. 🔗 Related articles from Watcher Guru and CoinDesk. #Bitcoin#USDC#Crypto#Trump#Coinbase#Binance#HesterPeirce#SEC#Decentralization#Finance#Investment#CriticalMetals#Aviation#Regulation#Liberty#Decentralized#Blockchain#CryptoNews#VC #Bitcoin#USDC#Crypto#Trump#Coinbase#Binance#HesterPeirce#SEC#Decentralization#Finance#Investment#CriticalMetals#Aviation#Regulation#Liberty#Decentralized#Blockchain#CryptoNews#VC

Venture Village Wall 🦄

@venturevillagewall · Post #4226 · 23.02.2025 г., 22:00

Biden Faces Bitcoin Chaos; SEC Crypto Shift 🚨 The Biden administration and U.S. Marshals Service can't account for billions in Bitcoin, raising concerns of theft. Meanwhile, 29.5M #XRP valued at $75.4M transferred to #Coinbase. 🔍 The SEC is reportedly dismantling its crypto enforcement program, potentially ending the Ripple appeal. Former SEC chief John Reed Stark highlights a shift in the SEC’s regulatory approach, with key figures removed from crypto litigation. Major changes expected, including a rebranding of the crypto unit and possible suspension of crypto enforcement. Expect deeper institutional instability and a new landscape for digital assets. 🔗Details on XRP Transfer | Leviathan News on Bybit Hack #Bitcoin#XRP#Coinbase#SEC#Crypto#Ripple#SOL#Bybit#Blockchain#Enforcement#Regulation#DigitalAssets#SECReform#Compliance#HesterPeirce#Laundering#WhaleAlert#CryptoInvestigation#MarketTrends#USTreasury#VC