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

Резултати

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

Пребарај: #emirati

当前筛选 #emirati清除筛选
L'Osservatorio - Italia

@Osservatorioitaliano · Post #25015 · 03.04.2026 г., 14:11

#Italia ❗️BREAKING ANSA - Blitz della Presidente del Consiglio Giorgia #Meloni (#FdI|ECR) nel Golfo. La ‘premier’ è appena atterrata a Gedda e nei prossimi giorni incontrerà i principali leader della zona e visiterà #ArabiaSaudita, #Emirati e #Qatar. Fonti di Palazzo Chigi sottolineano che la missione a sorpresa della premier mira, tra l'altro, al rafforzamento della sicurezza energetica nazionale. Si tratta della prima visita nella regione da parte di un leader di Ue, G20 e Nato dall'inizio del conflitto. Il Golfo rappresenta infatti una fonte cruciale di petrolio e gas per l'Italia e ha un ruolo determinante nell'andamento dei prezzi energetici globali. La missione punta anche a rafforzare le relazioni" con queste nazioni del Golfo e "ribadire il sostegno dell'Italia di fronte agli attacchi iraniani, consolidando al contempo un partenariato strategico sempre più solido. @OsservatorioItaliano

Addis Standard

@addisstandardeng · Post #21281 · 02.02.2026 г., 15:04

News: #Somaliland leader departs for #UAE, seeks deeper ties as regional stakes rise Somalia's northwestern breakaway region of Somaliland President Abdirahman Mohamed Abdullahi departed for the United Arab Emirates on Tuesday, leading a high-level delegation that includes cabinet ministers and senior advisers, his office said. The trip follows a formal invitation from the UAE government, with President Abdirahman Mohamed expected to attend a conference focused on development and intergovernmental cooperation. Officials said he is also scheduled to hold meetings in #Abu_Dhabi with senior #Emirati leaders to discuss strengthening bilateral relations. Talks are expected to center on development projects and investment, areas where the UAE has played a significant role in Somaliland's economy. Emirati logistics firm #DP_World has invested about $442 million in the expansion and ..... https://web.facebook.com/AddisstandardEng/posts/pfbid02vruBZ8aULb9h5RjA2RsY29mzkbAHJ12PxaQznHBY1Zrsq9GGTQzzwa8qRMyK9tUal

Addis Standard

@addisstandardeng · Post #21547 · 27.02.2026 г., 12:38

What #Sudan can teach #Ethiopia as #Eritrea conflict looms As African leaders gathered at the annual #African_Union summit in #Addis_Abeba last week under the seemingly non-urgent theme of “water sustainability,” there was only passing acknowledgement that “silencing the guns on our continent remains a challenge.” Yet the cadence of conflict — and the threat of new war — hung low over the horizon. It never felt proximate enough, however, to darken the mood of the festivities. Ethiopian Prime Minister Abiy Ahmed was keen to show off his clean and modern metropolis, financed and looking like a “mini-me” version of his #Emirati backers in #Dubai. As host of the three-day summit, Abiy’s heads of state guests showed deference by making no mention of his increasingly bellicose calls for sea access — and the indirect threat to Eritrea, its neighbor. Nor was there talk of Asmara’s response….. https://web.facebook.com/AddisstandardEng/posts/pfbid0obN5Kafo8UNTY59yKCGZdnA3LrbsDe5ztUgt28cTAUnTpDGbj4njfoj8yHH63sgnl

Maurizio Vezzosi

@mauriziovezzosi · Post #96 · 26.09.2019 г., 14:28

I recenti attacchi alle raffinerie saudite hanno evidenziato una notevole vulnerabilità delle strutture saudite e posto interrogativi anche sull affidabilità dei sistemi antimissile Patriot – di produzione statunitense – a cui ne è stata affidata la difesa. In questo senso, l’attacco alle raffinerie saudite rappresenta un duro colpo alla credibilità degli Stati Uniti, segnando inoltre un punto di svolta nella guerra dello #Yemen: un conflitto in cui ormai da anni si fronteggiano le forze governative – sostenute da #Arabia Saudita, #Emirati Arabi e #StatiUniti – e i ribelli #Houti sostenuti dall’#Iran. Un conflitto rispetto al quale l’Arabia Saudita non ha, per il momento, ammorbidito la propria linea oltranzista, nonostante le oltre 70.000 vittime già prodotte dal conflitto, la più grave crisi umanitaria attualmente esistente sul pianeta – secondo l’ ONU –, ed un atteggiamento ormai quasi disfattista da parte degli Emirati Arabi. Il mio articolo per l'Atlante geopolitico di Treccani http://www.treccani.it/magazine/atlante/geopolitica/Il_Vicino_Oriente_dopo_gli_attacchi_alle_raffinerie_saudite.html