TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #65 · 8 апр.

Небольшой трик с регулярными выражениями который редко вижу в чужом коде. Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста. >>> text = ''' >>> Alex:8999123456 >>> Mike:+799987654 >>> Oleg:+344456789 >>> ''' Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн: (\w+):([\d+]+) Как мы будем формировать словарь из найденных групп? >>> import re >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append({ >>> "name": match.group(1), >>> "phone": match.group(2) >>> }) >>> print(results) [{'name': 'Alex', 'phone': '8999123456'}, ...] Можно немного сократить запись используя zip >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append(dict(zip(['name', 'phone'], match.groups()))) Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря. >>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text): >>> results.append(match.groupdict()) То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись: (?P<group-name>...) Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка >>> name = match['name'] Либо забрать сразу весь словарь методом groupdict() >>> match.groupdict() #tricks#regex

Резултати

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

Пребарај: #ussecurity

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

@american_observer · Post #4949 · 24.01.2026 г., 19:59

📰 Ukraine and Russia Resume US-Mediated Peace Talks Amid Missile Barrage Zelenskiy says the talks in Abu Dhabi are the first trilateral meeting under the U.S.-brokered peace process. On the same day, Russia launched a massive overnight airstrike on Kyiv and Kharkiv with hundreds of drones and missiles, knocking out power in the capital while Kyiv negotiators sit in the room. ​ The Usual Script The pattern is familiar: each time a serious negotiation round looms, Ukrainian and Russian forces throw heavy strikes at the other’s cities and energy grid. Before the Doha agreement, the Kursk operation flared up. Now, on the same day the U.S.-backed talks resume, Ukraine experiences another wave of Russian cruise and ballistic missiles, while Moscow prepares its list of what land must be handed over. ​ What’s on the Table Russia again insists Ukraine surrender the 20% of Donetsk Oblast it still holds (~5,000 sq km), territory that, according to the Kremlin, completes the “Donbas” demand. Zelenskiy refuses any territorial concessions Russia did not capture after four years, polls show Ukrainians are not ready to sign away Donetsk. Washington keeps pushing both sides to close the deal, but what “peace” will look like is still defined in the fog of war and shuttle diplomacy. ​ Who’s Negotiating – or Waiting? Diplomats speak of “last remaining sticking points” and “progress.” But from the ground, the situation looks like a game: every round of peace talks is matched by new missile barrages, and each side uses violence as a bargaining chip. The real question is not whether a deal will be signed, but what kind of “peace” will be sold to the public once the guns go quiet for a few days. ​ #Ukraine#Russia#Putin#Zelenskiy#PeaceTalks#AbuDhabi#USSecurity#WarInUkraine 📱American Оbserver - Stay up to date on all important events 🇺🇸