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

Резултати

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

Пребарај: #deep

当前筛选 #deep清除筛选
Free Crypto Signals (Profitable Zone)

@btctradingclub · Post #26750 · 09.01.2026 г., 14:51

🚀🚀 123% Profit on #DEEP/USDT for our Premium Members on Binance Futures/Bybit/OKXX/Kucoin/Bitget ✅✅ All target completed 👁‍🗨Contact @primemod to enter the Premium Group for high quality SPOT & FUTURES Signals

Hashtags

Mountstorm notes

@mountstorm · Post #706 · 28.08.2023 г., 19:37

Don't avoid the cliches - they always work because they are clichés. In this post, you may face the author's offensive views about people's excessive repeated utterances that are widespread, calling attention to avert them. Basically, let it be on Instagram stories or Facebook profile pictures, you see people who post a picture of Yale, write Yale class of 2029 on the bio, and many similar actions. Holders could have no issue with posting them, and they are entitled to publish anything they care to do unless they don't publish political statements that can be conceived as an opposing point. By talking with people who already know the ups and downs of US admissions and hearing things I wasn't aware of, I realized that getting into a TOP-20 school requires hard work: nighttime study sessions, countless drafts of the final masterpiece, and dreadful deadlines. But everyone, not just me, can sense that people ignore the pain of those mentioned above and end up somewhere else where they have no desire to pursue their 4-year life. Rather than writing cool bio captions for NYU'28 or whichever college you dream of, spend time working on crucial components of the college application, check your essays to the expert, scrutinize what actions "99%" applicants are doing, and do the opposite or a bizarreness. My utterances may hurt souls, but I'm showing the truth (ridiculous actions). Now, get off this app and finalize your college list, which you care less to do. Two months left to catch the golden fish! #deep

Hashtags

耕读频道

@iGengdu · Post #786 · 13.02.2025 г., 12:27

#Deep Research #分享 分享:三款OpenAI Deep Research替代开源项目 https://github.com/nickscamara/open-deep-research https://github.com/mshumer/OpenDeepResearcher https://github.com/dzhng/deep-research 📢频道✈️群组☘️博客📬投稿

Hashtags

123•••56
ПретходнаСтраница 1 од 6Следна