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

Резултати

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

Пребарај: #ireland

当前筛选 #ireland清除筛选
POPULAR FRONT

@popularxfront · Post #6122 · 01.05.2026 г., 18:26

🇮🇪#Ireland: A 66-year-old man has been arrested and charged after a car bomb exploded outside a police station in Dunmurry, west Belfast, last Saturday. The perpetrator allegedly hijacked a delivery driver’s car and forced him to drive it to the location, where a gas cylinder had been placed inside and later detonated remotely. While some sources report he has been charged with attempted murder, others say he is also facing terrorism-related offences. Police believe the attack may be linked to the dissident republican group known as the New IRA. (via The Guardian, BBC & birminghammail)

Hashtags

POPULAR FRONT

@popularxfront · Post #6034 · 25.04.2026 г., 23:42

🇮🇪#Ireland: A suspected car bomb has exploded outside a police station in Dunmurry, Northern Ireland. Regional reports, including those from the Belfast Telegraph, state that the vehicle had been hijacked before being driven next to the police station, where it subsequently exploded. Police have cordoned off streets in the Kingsway area and are treating the situation as a “security incident.” No further details have been released at this time. (via Belfast Telegraph & @spicebag32; 📹 via @NiResponsevids on X)

Hashtags

POPULAR FRONT

@popularxfront · Post #5867 · 11.04.2026 г., 19:02

🇮🇪#Ireland: A man armed with a hammer breached security at Shannon Airport and climbed onto an American C-130 aircraft earlier today. Once on top of the plane, he attempted to damage it with the hammer. The man, who is in his 40s, was quickly arrested. No motive has been released, and his identity has not been disclosed.

Hashtags

POPULAR FRONT

@popularxfront · Post #5864 · 11.04.2026 г., 15:07

🇮🇪#Ireland: Up to 100 Gardaí were deployed to the Whitegate refinery, where protests have entered their fourth day amid rising fuel prices linked to the US and Israeli war against Iran. Footage shows Irish police forcibly attempting to remove trucks and tractors blocking the roads, with violent scenes breaking out. Officers can be seen kicking and stomping on farmers. Meanwhile, other videos appear to show protesters as young as 14 being pepper-sprayed by Gardaí.

Hashtags

POPULAR FRONT

@popularxfront · Post #5837 · 09.04.2026 г., 12:30

🇮🇪#Ireland: The Irish Army is set to be deployed across the country to remove heavy & agricultural vehicles blocking fuel depots, as protests over fuel prices enter their third day. Slow-moving convoys are targeting these sites over increasing fuel prices caused by the US and Israeli war against Iran. Police are now treating these actions as “blockades", with Gardaí (Irish police) reportedly requesting the assistance of the Irish army. In a statement, the Irish Minister for Justice said that once the army is deployed, people should not complain about any damage caused during the removal. (via CNN & limerickleader)

Hashtags

POPULAR FRONT

@popularxfront · Post #4697 · 24.01.2026 г., 11:11

🇮🇪#Ireland: ONH members fired a volley of shots in the Currynerin area of Derry last week. A 31-year-old man was arrested in connection with the event (though later released on bail) and a vehicle was seized. The PSNI have promised to increase ‘reassurance patrols as well as house-to-house enquiries and vehicle checkpoints in response. Repost via @spicebag32

Hashtags

POPULAR FRONT

@popularxfront · Post #4036 · 02.12.2025 г., 09:58

🇮🇪#Ireland: A new Irish militant group calling itself the "New Republican Movement" has announced its formation. In a video, where all members are armed, a masked man lists several motivations for creating the group, mostly focusing on mass immigration. They threaten Irish politicians with "immediate action", claiming to have their addresses. (via @real_eire on X)

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #1298 · 10.02.2025 г., 13:14

📍Ireland’s architectural heritage – a journey back to the 19th century🇮🇪 📏 📏 📏 📏 📏 📏 📏 📏 🌟With its stunning castles, ancient ruins, and charming Victorian buildings, Ireland offers a glimpse into the past, where history and beauty come together in every stone. 📏 📏 📏 📏 📏 📏 📏 📏 #Ireland🇮🇪@voyage

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #1200 · 19.12.2024 г., 13:14

📍Ireland’s architectural heritage – a journey back to the 19th century🇮🇪 📏 📏 📏 📏 📏 📏 📏 📏 🌟With its stunning castles, ancient ruins, and charming Victorian buildings, Ireland offers a glimpse into the past, where history and beauty come together in every stone. 📏 📏 📏 📏 📏 📏 📏 📏 #Ireland🇮🇪 @voyage

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #761 · 17.02.2024 г., 13:04

Ireland, Rock of Cashel 🇮🇪 The Rock of Cashel is one of the most visited landmarks in Ireland, also known as St. Patrick's Rock. It is also referred to as the Rock of Kings. ⛰ 🏰 Located in the ancient Celtic cathedral in County Tipperary, Ireland. The castle, built in the 4th century, was the royal residence of the provinces of southern Ireland; after 100 years, St. Patrick settled there. After Cromwell's army attacked, the castle complex became a symbol of the resilience and courage of the Irish people. The castle grounds still preserve residential buildings, structures for agricultural purposes, and the ruins of the cathedral. #Ireland @voyage

Hashtags

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