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 слични објави

Пребарај: #slextokens

当前筛选 #slextokens清除筛选
SLEX NEWS

@slex_io · Post #158 · 15.02.2024 г., 06:52

🚀The Time Is UP: Today is the First Day of SLEX Launchpad Sale! ☄️ ⚡️The wait is over! The first SLEX Launchpad officially starts today, February 15th at 12:00 UTC, after our Whitelist successfully closed with over 4000 participants. This marks the beginning of exceptional earning opportunities for our community🎉 🔥Premier Project Access: SLEX token holders, get ready for exclusive access to Tier-1 crypto projects. These handpicked projects offer a rare chance to invest in potentially profitable tokens. 💰Maximize Your Earnings: participate in the Launchpad to unlock staking rewards and additional trading benefits on SLEX Exchange. 📅 Important Reminder for Whitelist Members: 👀Due to the fact that token allocation and the time of the sale are limited, we recommend to deposit funds on your account in advance. ✍🏻If you did not create an account on SLEX yet, make sure that you create one under the email you specified in the Whitelist application form to be able to participate in token sale. #SLEX#LaunchpadLive#SLEXTokens#SLEXLaunchpad#SLEXWhitelist Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter

SLEX NEWS

@slex_io · Post #155 · 13.02.2024 г., 14:27

🚀Let the Sale Begin: The first SLEX Launchpad for 4000 Participants Starts on February 15th! 🎉 ⚡️We are thrilled to announce that the Whitelist on SLEX has been successfully closed with more than 4000 participants. And now we are at the finish line because it's only two days until the launch of the much-anticipated SLEX Launchpad!⚡️ 📈Mark your calendars and prepare to join SLEX Launchpad to get access to exceptional ways of earning: 🔥Access to Tier-1 Projects: SLEX token holders will gain exclusive access to Tier-1 projects, offering a gateway to the most promising and innovative crypto projects. 💰Staking Rewards and Trading Benefits: Token holders can get rewards from staking and additional trading bonuses at SLEX Exchange. 📅 If you are a Whitelist member check out email for more details and instructions about participation in the first SLEX Launchpad! #SLEX#LaunchpadAnnouncement#CryptoInnovation#SLEXTokens#TradingBenefits#SLEXLaunchpad#SLEXWhitelist Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter