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

Резултати

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

Пребарај: #isaias

当前筛选 #isaias清除筛选
Addis Standard

@addisstandardeng · Post #21058 · 13.01.2026 г., 13:19

News: Following months of mutual accusations, #Eritrean President Isaias Afwerki accuses #Ethiopia of declaring war, dismisses Red Sea narrative Eritrean President #Isaias Afwerki on Monday accused Ethiopia of declaring war on Eritrea and rejected narratives framing the tensions as a dispute over #Red_Sea access, in comments aired on Eritrean state television. Following an extended discussion on United States foreign policy, President Isaias turned to his deteriorating relations with Ethiopia’s ruling party. He rejected claims that tensions between the two countries are linked to access to the Red Sea, insisting that Eritrea harbors no such ambition. “For us, it is not directly about the Red Sea,” he said. The Eritrean leader accused Ethiopia’s ruling Prosperity Party of advancing a broader militarized agenda, claiming that armed conflicts have persisted across the country despite the signing of the Pretoria peace agreement. Isaias further alleged that ... Read more: https://addisstandard.com/?p=54519

Addis Standard

@addisstandardeng · Post #21496 · 23.02.2026 г., 08:32

News: #Saudi deputy foreign minister meets #Ethiopian FM week after Isaias talks in Asmara Saudi Arabia’s Vice Minister of Foreign Affairs, Waleed A. M. Elkhereiji, met with Ethiopia’s Minister of Foreign Affairs, Gedion Timothewos, in Addis Abeba, a week after holding talks with #Eritrean President #Isaias Afwerki in #Asmara. According to a statement from the Ethiopian Ministry of Foreign Affairs, the two officials discussed the “strong and longstanding bilateral relations” between Ethiopia and the Kingdom of Saudi Arabia, underscoring the importance of elevating ties to “a new high.” They also exchanged views on regional peace & security issues of mutual interest. Ethiopia’s Minister of Foreign Affairs offered no additional information in the statement. The meeting comes a week after Saudi Vice Foreign Minister Waleed A. M. Elkhereiji held talks in Asmara with Eritrean President... Read more: https://addisstandard.com/saudi-deputy-foreign-minister-meets-ethiopian-fm-week-after-isaias-talks-in-asmara/

TrilocosxJesús ✨

@trilocosxjesus · Post #6499 · 09.08.2025 г., 16:17

🚀✨ ¡Comenzamos una nueva etapa en nuestra serie de las Sagradas Escrituras! Hoy nos adentramos en los Libros Proféticos con uno de sus gigantes: Isaías. Junto a Daniel Osorio, descubriremos su mensaje lleno de esperanza y promesa mesiánica. 📅 Hoy | 🕑 2:00 p.m. 📻 Tu Emisora Minuto de Dios 🎙#LaCatequesis 📖 “El pueblo que caminaba en tinieblas vio una gran luz” (Is 9,1). #fesencillavidailuminada#minutodediosmed#trilocosxjesus#Biblia#Isaias#Profeticos#PalabraQueTransforma