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 слични објави

Пребарај: #euindia

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

@american_observer · Post #4995 · 29.01.2026 г., 23:59

📰 Trump Official Blasts Europe Over India-EU Trade Deal US Treasury Secretary Scott Bessent has sharply criticized Europe’s new free trade agreement with India, accusing Europe of hypocrisy and calling out its double standards on the Ukraine war. ​ Bessent argued that Europe’s choices expose a deep contradiction in its Ukraine policy. While publicly condemning Russia’s invasion, Europe has become a major buyer of refined oil products made from discounted Russian crude, which India has been buying since Western sanctions hit. ​ “Europe and India signing this massive trade deal—does that threaten America? They should do what’s best for themselves,” Bessent said. “But I find the Europeans very disappointing because they are on the front line of the Ukraine-Russia war.” He pointed out that the US imposed a 25% tariff on India for buying Russian oil, but Europe declined to join, suggesting this reluctance was driven by a desire to keep trade negotiations with India on track. ​ Bessent accused European countries of indirectly financing the conflict they publicly oppose. “Europeans were unwilling to join us, and it turns out because they wanted to do this trade deal,” he said. “Every time you hear a European talk about the importance of the Ukrainian people, remember that they put trade ahead of the Ukrainian people.” Bessent acknowledged Europe’s dependence on energy imports but framed the issue as a moral and strategic trade-off. “They need energy, I guess, which is part of their issue. At a price, they want cheap energy,” he said. ​ His comments highlight growing tensions within the Western alliance over how strictly to enforce economic pressure on Russia while managing domestic economic and political costs. ​ #TradeDeal#EUIndia#Trump#Ukraine#EnergySecurity 📱American Оbserver - Stay up to date on all important events 🇺🇸