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

Резултати

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

Пребарај: #uel

当前筛选 #uel清除筛选
Football Daily News

@FootyNews · Post #112806 · 18.05.2023 г., 22:09

Sevilla have won 100% of the #UEL semi-finals they've contested: ◉ 2005/06 v Schalke ◉ 2006/07 v Osasuna ◉ 2013/14 v Valencia ◉ 2014/15 v Fiorentina ◉ 2015/16 v Shaktar ◉ 2019/20 v Man Utd ◉ 2022/23 v Juventus And they've gone on to lift the trophy every single time. 🤯https://t.co/QoHm1XFxnh

Hashtags

Football Daily News

@FootyNews · Post #112798 · 18.05.2023 г., 19:09

RT @Squawka_Live: 19-year-old England U20 international Samuel Iling-Junior starts for Juventus for only the third time. Thrown in at the deep end. 🤿 #UELhttps://t.co/m5XW1Rx6Cihttps://t.co/bBFN7rfQGO

Hashtags

Football Daily News

@FootyNews · Post #112594 · 11.05.2023 г., 20:09

RT @Squawka_Live: Lucas Ocampos first-half by numbers vs Juventus: 100% passing accuracy 100% dribbles completed 6 touches in opp. box (most) 5 shots (most) 5 duels won (Sevilla most) 2 chances created (joint-most) 1 assist 0.73 xG Posting FT stats at HT. 🥶 #UELhttps://t.co/0SXs7yyirm

Hashtags

Football Daily News

@FootyNews · Post #112593 · 11.05.2023 г., 19:10

RT @Squawka_Live: Juventus' record at home in the Europa League since 2009: 🤝 0-0 ✅ 3-1 ✅ 1-0 ✅ 1-0 🤝 3-3 🤝 1-1 🤝 0-0 ✅ 2-0 🤝 1-1 ✅ 2-1 🤝 0-0 🤝 1-1 ✅ 1-0 ✅ 1-0 Mission impossible for Sevilla? #UELhttps://t.co/ulnbRPSOGg

Hashtags

Football Daily News

@FootyNews · Post #111952 · 20.04.2023 г., 22:09

RT @Squawka_Live: Paulo Dybala's game by numbers vs Feyenoord: 47 minutes played 38 touches 6 shots 3 duels won 3 chances created 3 shots on target 1 goal 0.31xG Impact. 💥#UELhttps://t.co/awnOgtSlY4

Hashtags

Football Daily News

@FootyNews · Post #111949 · 20.04.2023 г., 22:09

RT @Squawka_Live: No Premier League player has made more errors leading to a goal across all competitions than David De Gea since the start of last season (5). 😬#UELhttps://t.co/4g3ld0CKW4

Hashtags

Football Daily News

@FootyNews · Post #111945 · 20.04.2023 г., 21:10

RT @Squawka_Live: Man Utd in the first leg vs Sevilla: ◉ Score two own goals Man Utd in the second leg vs. Sevilla: ◉ Commit two errors leading to goals Shooting themselves in the foot. 🔫#UELhttps://t.co/Bv4VnTGCbl

Hashtags

Football Daily News

@FootyNews · Post #111943 · 20.04.2023 г., 20:09

RT @Squawka_Live: Erik Lamela created more chances than any other player in the first half vs. Man Utd (3). He also provided the assist for Youssef En-Nesyri, his first for Sevilla this season. 🅰️#UELhttps://t.co/baxztemlkr

Hashtags

Football Daily News

@FootyNews · Post #111941 · 20.04.2023 г., 18:09

RT @Squawka_Live: Sevilla XI: Bono; Navas, Bade, Marcao, Acuna; Gudelj, Fernando; Ocampos, Rakitic, Lamela; En-Nesyri. Man Utd XI: De Gea; Wan-Bissaka, Maguire, Lindelof, Dalot; Eriksen, Casemiro, Sabitzer; Antony, Martial, Sancho. #UEL

Hashtags

12
ПретходнаСтраница 1 од 2Следна