Небольшой трик с регулярными выражениями который редко вижу в чужом коде.
Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста.
>>> 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 hours ago, James Fickel (@jamesfickel) swapped another 350 $WBTC for 6,905 $ETH ($24.4M) at ~$3,534 as the $ETH price soared 20% (24H)!
Note that since Dec 30, 2023, the founder of Amaranth Foundation has been bullish on the ETH/BTC trading pair, borrowing and exchanging 2,741 $WBTC for 50,688 $ETH at an ETH/BTC ratio cost of 0.054.
Follow @spotonchain and visit James Fickel’s address at https://platform.spotonchain.ai/en/profile?address=0xd85351181b3f264ee0fdfa94518464d7c3defada
#EthereumETF#Approval
🎧⤴
Ethereum ETF Set to Ignite Prices – Could ETH Hit $4,500?
Monochrome Asset Management has filed to launch an Ethereum ETF in Australia under the ticker "IETH." If approved, the ETF will offer a regulated way for retail investors to buy into Ethereum, marking a crucial expansion of crypto products in Australia. Analysts predict this could push ETH prices towards $4,500, especially if Bitcoin continues its upward momentum.
Verse 1:
ETF drop, watch the markets shake,
IETH comin’, time to raise the stake,
Aussie brokers lined up, ready to go,
Regulated crypto, yeah, it’s the show.
Chorus:
Will ETH hit that 4-5-0-0?
Markets movin’ fast, now they wanna know,
Monochrome pushin’ for the big rise,
Crypto to the moon, no surprise.
Verse 2:
Bitcoin’s on fire, aim for that 100K,
Ether right behind, it’s a bull run day,
Dual-access cash flow, simple as can be,
Australian retail gonna stack that ETH, see?
Chorus:
Will ETH hit that 4-5-0-0?
Markets movin’ fast, now they wanna know,
Monochrome pushin’ for the big rise,
Crypto to the moon, no surprise.
Bridge:
Hold tight, watch that price climb high,
Regulated ETF, no more askin’ why,
Cash or in-kind, take your pick,
Ethereum’s future, man, it’s lookin’ slick.
Verse 3:
From Bitcoin to ETH, it’s all on track,
Regulators here, no more lookin’ back,
Australia leads, yeah, they’re paving the way,
Crypto in the mainstream, here to stay.
Chorus:
Will ETH hit that 4-5-0-0?
Markets movin’ fast, now they wanna know,
Monochrome pushin’ for the big rise,
Crypto to the moon, no surprise.
#EthereumETF
#CryptoInvestment
#TONCryptoNewsRapStyle
🎧@toncoin_rap
🌐Breaking News: Investment bank TD Cowen predicts a delay in the U.S. SEC approval for an #Ethereum spot ETF.
Analysts suggest the SEC might be cautious, observing outcomes from #Bitcoin ETFs first, before greenlighting #Ethereum or other crypto ETFs.
#CryptoNews#ETFApproval#SEC#EthereumETF
-
Crypto GALAXY
Crypto Funds Struggle Compared to Bitcoin
OKX's founder Star claims no crypto fund has outperformed Bitcoin over the last decade, predicting a 100x growth for the industry. He acknowledged feedback on OKB's lack of use cases and poor listings. A new secret business line for OKX is set to launch in February.
In other news, Ethereum spot ETFs saw a net outflow of $39.432 million, while Bitcoin ETFs faced a larger outflow of $284 million. Notably, BlackRock's ETHA and IBIT ETFs saw significant inflows.
Read more about OKX's updates here, Ethereum's ETF activity here, and Bitcoin's ETF activity here.
#OKX#Bitcoin#Ethereum#Crypto#ETFs#BlackRock#OKB#NFTs#Web3#DeFi#Soneium#S.BLOX #Blockchain#Investing#Finance#BitcoinETF#EthereumETF#VC#AI
🚀 Morgan Stanley Explores Tokenized Money-Market Fund After Bitcoin ETF Launch
Morgan Stanley, managing $9.3 trillion in client assets, is considering launching a tokenized money-market fund following its recent introduction of a spot Bitcoin ETF. According to NS3.AI, Amy Oldenburg from Morgan Stanley highlighted the bank's interest in tax-loss harvesting for digital assets through its subsidiary, Parametric. Data from Farside Investors indicates that the new Bitcoin ETF has attracted approximately $46 million in net inflows since its launch on Wednesday. Additionally, Morgan Stanley submitted applications in January for ETFs linked to Ethereum and Solana.
#MorganStanley#TokenizedMoneyMarketFund#BitcoinETF#DigitalAssets#TaxLossHarvesting#EthereumETF#SolanaETF#Parametric#NS3AI#FarsideInvestors#CryptoInvesting#BTC#ETH#SOL