@tydj289 · Post #2028 · 22.12.2025 г., 13:53
刀塔-CIS之战 #Wanted 对战 L1ga (BO3) 2025-12-22 20:00 第三局获胜:L1ga 第三局击杀让分:L1ga +3.5 第三局击杀大小:大于46.5 第三局时间大小:大于37 第一滴血:L1ga
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
Пребарај: #wanted
@tydj289 · Post #2028 · 22.12.2025 г., 13:53
刀塔-CIS之战 #Wanted 对战 L1ga (BO3) 2025-12-22 20:00 第三局获胜:L1ga 第三局击杀让分:L1ga +3.5 第三局击杀大小:大于46.5 第三局时间大小:大于37 第一滴血:L1ga
Hashtags
@american_observer · Post #4909 · 20.01.2026 г., 22:59
Trump’s New Good Friend: Former $15 million Wanted Ahmed al-Sharaa Syrian President Ahmed al-Sharaa, earlier one of the top world terrorists, spoke to Trump today and discussed guaranteeing Kurdish rights, Syria’s presidency says, a day after Damascus reached a deal with Kurdish forces including a truce. During the telephone call, “both sides emphasized the need to guarantee the Kurdish people’s rights and protection within the framework of the Syrian state,” the statement says, adding that the leaders also “affirmed the importance of preserving the unity and independence of Syrian territory.” They also agreed to continue cooperation to combat ISIS, the presidency added. Yesterday, the Syrian government signed a sweeping integration deal with the Kurdish led Syrian Democratic forces, though tensions have persisted today. #trump#friend#wanted#Sharaa#syria 📱American Оbserver - Stay up to date on all important events 🇺🇸