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

Резултати

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

Пребарај: #onton

当前筛选 #onton清除筛选
TONlines – News

@tonlines · Post #6777 · 15.04.2025 г., 13:11

bemo: ONTON and ONION Roadmap Launch #ONTON#NFT The bemo channel announces the launch of the Genesis ONIONs x ONTON roadmap, marking an important milestone for the platform. With over 100 partners and more than 3,000 NFTs already reserved, the roadmap outlines the future developments for the ONTON platform and promises significant value for Genesis NFT holders. Source: link @tonlines

Hashtags

🏅Distribution of unique SBT badges to ONTON & GVWS Marathon participants has begun! 🤝 The ONTON team, together with GVWS, launched the distribution of custom badges in the Soulbound Token (SBT) format to everyone who participated in the marathon dedicated to the launch of the Constructor. These badges serve as official confirmation of activity in the project and can play an important role in future drops, bonuses and participation in the ecosystem. To get your badge: ✅ You need to log in and go through the steps in the bot — @theontonbot ✅ Then go to your personal account on getgems.io ✅ Find GVWS SBT and click the Claim NFT button 😋The badge is displayed in three places at once: — in the GVWS profile — in ONTON — in Ton Society 💪 Participants who completed the marathon and already interacted with the ONTON bot received a push notification with the ability to brand. Those who did not participate in ONTON activities, but fulfilled the conditions of the marathon, will receive a notification later — via the bot @gvws_bot. More details: here #SBT#Marathon#TON#ONTON

🙏SBT ONTON in real time! 🔍 Our chat has a bot that monitors the emergence of new SBTs in real time — they appear instantly along with passwords! ❤️ No need to search for them in different chats anymore - just join our community and get valuable Soul Bound Tokens to your wallet, so that you can get a drop for them later! 🟣Claim your SBT ONTON now! #TON#ONTON#SBT#Airdrop#Web3#TONCommunity