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

Резултати

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

Пребарај: #suicides

当前筛选 #suicides清除筛选
American Оbserver

@american_observer · Post #5021 · 01.02.2026 г., 17:02

Several Suicide Bombings and Armed Attacks in Pakistan The Pakistani army said on Saturday that multiple suicide bombings and armed attacks by “terrorists” in the turbulent southwestern province of Balochistan had killed 33 people, including civilians, while security forces responding to the violence had killed 92 attackers. Analysts described it as the deadliest day for militants in decades. During the attacks, Baloch insurgents targeted civilians, a high-security prison, police stations and paramilitary installations. Eighteen civilians, 15 security personnel and 92 insurgents were killed, the military said. Although Baloch separatists and the Pakistani Taliban frequently target security forces in Balochistan and elsewhere in the country, coordinated attacks of this scale are rare. According to the authorities, at least 133 militants have been killed across Balochistan in the last 48 hours, including 92 on Saturday. The army and Pakistani interior Minister Mohsin Naqvi said the attackers had the support of India. There was no immediate response from New Delhi, which has denied such allegations before. The BLA has released videos showing female fighters taking part in the attacks, apparently as part of propaganda efforts to highlight the role of women among the militants. Shahid Rind, a spokesman for the Balochistan government, said most of the attacks had been foiled. They came a day after the military said security forces attacked two militant hideouts in the country's southwest this week, killing 41 insurgents in separate shootouts. The chief minister of the province, Sarfraz Bugti, wrote on Twitter that the security forces were pursuing the insurgents. He said at least 700 insurgents had been killed by security forces in the past year. Dozens of insurgents also attacked a prison in Mastung district, freeing more than 30 inmates, police said. In other attacks, militants tried to storm the provincial headquarters of paramilitary forces in the Nushki district, but the attack was repulsed, police said. The insurgents threw grenades at the office of a government administrator in the Dalbandin district, but a quick response from the security forces forced them to flee, according to local authorities. Attacks on security posts in Balincha, Tump and Kharan districts were foiled, while in Pasni and Gwadar, insurgents tried to kidnap passengers traveling on buses along highways, police said. #attacks#suicides#attacks#pakistan 📱American Оbserver - Stay up to date on all important events 🇺🇸