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

Резултати

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

Пребарај: #iraq

当前筛选 #iraq清除筛选

伊拉克的藥材鋪 (地點: Karbala) Karbala 是巴格達以南一百公里的一個什葉派聖城。 基本上,全世界有草本植物的地方,也有自己一套的經驗醫學和本草綱目。伊拉克的「米索不達美亞」是暫時考古之中, 承認的最早出現系統及文字的人類文明, 那時他們已經懂得「做手術」。 #Iraq

Hashtags

POPULAR FRONT

@popularxfront · Post #6196 · 08.05.2026 г., 16:27

🇮🇶#Iraq: Hajaj Ahmed Hardan al-Tikriti, widely known among survivors as "Saddam Hussein’s personal butcher" was brought before the Rusafa Criminal Court in Baghdad over crimes linked to the Anfal genocide against the Kurds. A former warden at the notorious Nugra Salman prison in Iraq’s southern Muthanna province, he is accused of overseeing torture and carrying out executions, forced disappearances, starvation, and the abuse of thousands of Kurdish detainees during the late 1980s. Since his arrest on July of last year, after decades in hiding, al-Tikriti has appeared multiple times before the Rusafa Court in connection with atrocities committed at Nugra Salman prison. Around 221 relatives of Anfal victims from several Kurdish regions attended the court session wearing traditional Kurdish clothing, demanding justice for the massacres and crimes committed against the Kurdish population. Attached footage shows Hajaj in handcuffs next to the Nugra Salman Prison. (via Rudaw & @kurdishactivism_ on IG)

Hashtags

POPULAR FRONT

@popularxfront · Post #6080 · 29.04.2026 г., 06:56

🇮🇶#Iraq: The “Guardians of Blood Brigades” have struck a communication tower at the US Victoria Base in Baghdad using a fiber-optic drone armed with an RPG warhead. (via @war_noir)

Hashtags

POPULAR FRONT

@popularxfront · Post #6002 · 24.04.2026 г., 01:17

🇮🇶#Iraq: The Kurdistan National Army headquarters in Chamshari was struck by a drone last night. So far, no information has been released regarding who launched the attack. (via @KurdishFrontNews)

Hashtags

POPULAR FRONT

@popularxfront · Post #5989 · 22.04.2026 г., 21:10

🇮🇶#Iraq: Footage showing drone interceptions over Erbil in Iraqi Kurdistan after an alleged massive drone attack.

Hashtags

POPULAR FRONT

@popularxfront · Post #5850 · 10.04.2026 г., 09:18

🇮🇶#Iraq: Footage shows US forces attempting to shoot down drones over Erbil Governorate in Iraq's Kurdistan overnight. Several reports state that the drones belong to Iran-backed militias, with one of the most active groups in Iraq lately being the Guardians of Blood Brigades. (via Archer83Able on X)

Hashtags

POPULAR FRONT

@popularxfront · Post #5817 · 08.04.2026 г., 07:59

🇮🇶#Iraq: The "Islamic Resistance in Iraq" has carried out several attacks against US bases in Iraq, as well as in the Kurdistan Region, overnight. The militants used cruise missiles and kamikaze drones in the attacks. (via @war_noir)

Hashtags

POPULAR FRONT

@popularxfront · Post #5728 · 02.04.2026 г., 23:30

🇮🇶#Iraq: Footage released by the Islamic Resistance in Iraq (IRI) shows a drone strike targeting a fuel tank at the US Victory Camp base near Baghdad Airport. (via @conflictarchive)

Hashtags

123•••10•••202122
ПретходнаСтраница 1 од 22Следна