@animal_fighting · Post #281 · 29.09.2022 г., 15:04
Crocodile VS Man One more way to deal with a toothy trespasser😀 #crocodile🐊
Hashtags
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
Пребарај: #crocodile
@animal_fighting · Post #281 · 29.09.2022 г., 15:04
Crocodile VS Man One more way to deal with a toothy trespasser😀 #crocodile🐊
Hashtags
@animal_fighting · Post #22 · 03.05.2022 г., 11:03
Crocodile VS Crocodile There hardly is a winner... #crocodile
Hashtags
@SukoFaultyArtLair · Post #4503 · 01.12.2019 г., 20:52
https://www.furaffinity.net/view/31997665/ #female#crocodile
Hashtags
@animal_fighting · Post #288 · 02.10.2022 г., 15:04
Lion VS Crocodile A dangerous opponent #lion🦁#crocodile🐊
Hashtags
@animal_fighting · Post #159 · 16.07.2022 г., 15:04
Crocodile VS Lions Too big and too sharp-toothed even for three lions #lion🦁#crocodile🐊
Hashtags
@animal_fighting · Post #94 · 11.06.2022 г., 07:03
Crocodile VS Lions It's too dangerous even for a lion pride #crocodile#lion
Hashtags
@animal_fighting · Post #29 · 07.05.2022 г., 07:03
Lions VS Crocodile When a prey is too dangerous even if being outnumbered #lion#crocodile
Hashtags
@animal_fighting · Post #333 · 09.11.2022 г., 19:04
Dog VS Crocodile Good reaction can save life... #dog#crocodile
Hashtags
@animal_fighting · Post #187 · 30.07.2022 г., 15:04
Dog VS Crocodile Terror of the jungle 😁 #dog🐕#crocodile🐊
Hashtags
@animal_fighting · Post #52 · 18.05.2022 г., 11:04
Buffalo VS Crocodile Unlucky hunting #buffalo#crocodile
Hashtags
@zigou23 · Post #136 · 28.04.2021 г., 03:27
抹茶旦旦 #鳄鱼#crocodile https://t.me/addstickers/mochadandan https://t.me/addstickers/mochadandan2 https://t.me/addstickers/mochadandan3 https://t.me/addstickers/mochadandan4_32 透明 https://t.me/addstickers/mcdd_tz 动态 https://t.me/addstickers/dxdongtai11_by_fStikBot https://t.me/addstickers/MoChaDanDan_EYu https://t.me/addstickers/mochadandan4
Hashtags
@animal_fighting · Post #268 · 25.09.2022 г., 10:04
Cat VS Crocodile Hunger makes one more courageous😀 #cat🐈#crocodile🐊
Hashtags