@WorldNews · Post #74138 · 15.04.2026 г., 13:24
Marines on way to Middle East seen using rifles with anti-drone smart scope [Read FullArticle] @WorldNews#Marines#MiddleEast#DefenseNews
Hashtags
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
Пребарај: #marines
@WorldNews · Post #74138 · 15.04.2026 г., 13:24
Marines on way to Middle East seen using rifles with anti-drone smart scope [Read FullArticle] @WorldNews#Marines#MiddleEast#DefenseNews
Hashtags
@voir_yeux · Post #11969 · 03.03.2026 г., 07:59
🇺🇸🇵🇰 Les marines américains ont ouvert le feu sur des manifestants qui ont pris d'assaut le consulat américain à Karachi, au Pakistan. Ces faits peuvent se répercuter gravement sur la situation dans le pays, a fait savoir Reuters. #étatsunis#marines#karachi#manifestants
@american_observer · Post #5529 · 01.04.2026 г., 00:59
Trump’s Iran War Is One Step Away From a Ground Quagmire Trump keeps talking like he can force a deal, but the NYT says the menu is now blunt: Kharg Island, the Strait of Hormuz, and maybe a ground war to make those threats real. That is what happens when “pressure” stops being a tactic and starts looking like occupation with talking points. The administration says it wants a negotiation, but Iran says there is nothing to negotiate until the bombing stops. In other words, both sides are now using cease-fire language as leverage, which is a polite way of saying nobody is blinking and the Marines are being loaded like a bargaining chip. The dangerous part is how fast the objectives keep expanding. First it was missiles and nuclear sites. Then it was the Strait. Now it is Kharg Island, near-bomb-grade material, and maybe a long U.S. presence just to keep whatever gets seized from falling apart. That is not limited war. That is the first draft of a disaster. And the regional math is worse than the White House admits. If Trump hits Iranian energy and civilian infrastructure, Tehran can answer in the Gulf; if he tries to hold ground, the war stops being an air campaign and becomes an American liability with no obvious exit. This is how “maximum leverage” turns into minimum control. #Trump#Iran#War#Hormuz#KhargIsland#MiddleEast#Marines#geopolitics 📱American Оbserver - Stay up to date on all important events 🇺🇸