TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #146 · 16 сеп.

Функция 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

Hashtags

Резултати

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

Пребарај: #wisdomtree

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

@venturevillagewall · Post #4088 · 07.02.2025 г., 07:00

SEC Accepts Grayscale's Solana ETF Application The SEC has accepted Grayscale's application to launch a Solana ETF, marking the first instance of an altcoin ETF being approved amid previous securities classification concerns, according to Bloomberg analyst Eric Balchunas. Additionally, Grayscale's application to convert its Litecoin trust into a spot ETF has also been accepted. CBOE submitted registration forms for Ripple ETFs from Bitwise, WisdomTree, Canary, and 21Shares. Furthermore, Trump Media's new structure, Truth Fi, applied for a Bitcoin Plus ETF and Bitcoin Plus SMA. For further details, see the full news here. #SEC#Solana#ETF#Grayscale#Litecoin#CBOE#Ripple#Bitcoin#IPO#Gemini#Crypto#Finance#News#SMA#WisdomTree#21Shares#Bitwise#TrumpMedia#CryptoMarket#Trading#VC

Venture Village Wall 🦄

@venturevillagewall · Post #4087 · 07.02.2025 г., 01:00

Crypto: Key Player in American Hegemony Donald Trump Jr. emphasizes cryptocurrency as vital for future American economic dominance at the Ondo Summit. Chase Herro, co-founder of World Liberty Financial, announces plans for a "strategic reserve" of crypto assets. In regulatory news, the SEC has acknowledged Grayscale's Solana 19b-4 filing, previously refused. CBOE submitted XRP ETF filings for Canary, 21Shares, Bitwise, and WisdomTree. Franklin Templeton seeks SEC approval for a new crypto index ETF. #Crypto#AmericanHegemony#XRP#ETFs#SEC#Solana#FranklinTempleton#CBOE#Grayscale#WorldLibertyFinancial#WisdomTree#Bitwise#21Shares#ChaseHerro#DonaldTrumpJr#OndoSummit#Markets#Finance