Функция sub в regex может принимать функцию в качестве аргумента repl.
📄 Из документации:
If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string.
То есть для каждого совпадения будет вызвана функция для вычисления замены вместо замены на одну и ту же строку для всех совпадений.
Иными словами, для замены разных совпадений на разные строки не потребуется запускать re.sub() много раз для каждой строки замены. Достаточно определить функцию, которая вернёт строку для каждого из совпадений.
Описание слишком запутанное🤔, давайте лучше рассмотрим на простом примере:
Создаем карту замены. То есть какие строки на какие требуется менять.
remap = {
'раз': '1',
'два': '2',
'три': '3',
'четыре': '4',
'пять': '5',
}
Пишем функцию поиска строки для замены. Единственным аргументом будет объект re.Match.
Используя данные этого объекта мы вычисляем замену on-the-fly!
def get_str(match: re.Match):
word = match.group(1)
return remap.get(word.lower()) or word
Пример текста.
text = '''Раз Два Три Четыре Пять
Вместе будем мы считать
Пять Четыре Три Два Раз
Мы считать научим вас
'''
Теперь запускаем re.sub и вместо строки замены (repl) подаём имя функции.
(Данный паттерн ищет отдельные слова в тексте)
>>> print(re.sub(r'(\w+)', get_str, text))
1 2 3 4 5
Вместе будем мы считать
5 4 3 2 1
Мы считать научим вас
Думаю, достаточно наглядно 🤓
#libs#regex
#FTX
Суд отклонил запрос SBF на новый процесс
Федеральный судья отказал Сэму Бэнкману-Фриду в проведении нового судебного разбирательства.
В решении суд прямо раскритиковал аргументы защиты, назвав их «дико конспирологическими».
Запрос SBF был связан с попыткой оспорить вынесенный ранее приговор по делу FTX, но суд не нашел оснований для пересмотра.
FTX Executives Get Reduced Prison Sentences
⚖️ Former FTX executives Ryan Salame and Caroline Ellison have had their prison sentences reduced. Salame will serve until March 2031, a year less than initially sentenced. Ellison's term is cut by three months, allowing her to be released in July 2026. Speculations suggest these reductions may stem from cooperation with authorities against Sam Bankman-Fried. For more details, visit ForkLog.
#FTX#Crypto#VC
#FTX merges #SOL
The bankrupt exchange withdrew $160 million worth of coins from stacking a couple of days ago and this morning brought $30 million on the exchange
We can see that #Bitcoin has generally been increasingly dominant over the past few years. Since the #FTX Collapse in November 2022, #BTC has increased its market cap dominance from 38.9% to 49.8%.
On the other hand, #ETH has maintained its market cap dominance, ranging from 18.9% to 18.2%. It is mainly Altcoins that have lost market share in the crypto markets with their market cap dominance dropping from 28.3% to 24.2%, while Stablecoins have also decreased their share from 13.9% to 7.8%.
By Crypto Australia
🚨🚨#FTX and #Alameda transferred out $38.5M worth of 7 assets to exchanges ~6hrs ago:
• 750,000 $SOL ($31.2M)
• 325,501 $ENS ($2.76M)
• 10.1M $GMT ($2.22M)
• 642,702 $LDO ($1.26M)
• 288,211 $APE ($410K)
• 127,407 $BADGER ($365K)
• 555,342 $BNT ($323K)
Overall, as of Nov 8, #FTX and #Alameda have transferred out $350M worth of 36 assets to exchanges.
👉 More details: https://platform.spotonchain.ai/signal-details/ftx-and-alameda-research-further-moved-altcoins-to-exchanges-4711
$400M theft, FTX bankruptcy & fried leadership! 😱 Scary preview of crypto chaos or cautionary tale? Stay alert, traders! 📈#CryptoNews#FTX#Trading#Cryptocurrency
📈BTC price at the time of this post: $43095
👉Continue reading
🚨#FTX and #Alameda Research just deposited 44.19M $CRO ($4.17M) to #Coinbase ~20 mins ago.
Overall, FTX and Alameda have deposited 13.99M worth of $ETH, $CRO, $MATH, $MPL, and $BLZ to Coinbase in the past 2 weeks.
👉 More details: https://platform.spotonchain.ai/en/signal-details/ftx-and-alameda-moved-cro-to-coinbase-prime-16235
📰 NEWS
😨 .Sentiment: The cryptocurrency market is experiencing a historical level of fear.
🟤 Mt Gox transferred over 47,000 BTC to another wallet late on Thursday evening, according to Arkham Intelligence. This is happening before his upcoming return of $9 billion worth of bitcoins to creditors.
Over the past 24 hours, 232,804 traders have been liquidated, the total amount of liquidations amounted to $672.22 million.
💥 This is the largest #BTC liquidation event since the collapse of #FTX.
Galaxy Research Director: Mt.Gox bitcoins will be stored in the long term, not sold. Details:
Alex Thorne suggested that this transaction (at ~47K) It was transferred to one of the distribution agents. If this is true, we may see more such transfers totaling about 100,000, unless the custodian reconfigures the internal wallets unnecessarily, as was done on May 27. I still believe that Mt.Gox bitcoins are more likely to be stored in the long term rather than sold
💰Over the past month, 500 thousand new tokens have been created on #Solana.
📢 .The Hamilton crypto startup has issued tokenized U.S. Treasury bonds on bitcoin's second-tier blockchains. Hamilton U.S. T-Bills (HUST) bonds are available on Stacks, Core and BoB L2 networks.
‼️ Nate Geraci, president of The ETF Store, wrote that he does not rule out the launch of the #Solana spot #ETF around this time next year.
After being dormant for 5 years, a whale deposited 1,000 $BTC ($67.64M) into #Bitfinex, making a profit of $38.35M
The whale initially withdrew this $BTC for $29.28M from #Bitstamp and #FTX.
https://intel.arkm.com/explorer/address/3C9hNKdbBe6aR7sdkoXCQwFF1RakBUsziY
https://x.com/OnchainLens/status/2025167951964635250
Follow @onchainlens for more onchain updates
Two institutions #Celsius and #FTX moved out a total of $59.06M in 6 assets to CEX in the past 8 hours!
1. Celsius further moved 22,500 $ETH ($50.78M) to #Coinbase at $2,257 ~8 hours ago.
➡️ Now, Celsius only holds around 39,969 $ETH ($90.9M) in address 0xdb3.
👉 More details here
2. FTX and Alameda Research moved out $8.28M in 6 assets, including $ETH, $OKB, $MTL, $PROM, $YFII, and $CREAM in the past 2 hours.
➡️ Overall, FTX and Alameda Research have moved out $707M worth of 91 tokens since October 24, 2023.
👉 More details here
Want to be updated with latest whale movements? Follow @spotonchain and visit us via https://platform.spotonchain.ai/en