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

Пребарај: #domar

当前筛选 #domar清除筛选
Eva Karene Bartlett

@EvaKarene_Bartlett · Post #30442 · 11.04.2026 г., 09:17

#Damascus : Ismaili Man Killed by Gunmen, Amid Rising Attacks Targeting the Ismaili Community Madin Ismail Zino, 56, originally from the city of Salamiyah in W. #Hama countryside, has died from critical gunshot wounds he sustained a week ago in e. #Domar area of Damascus. He passed away today April 10, 2026. Since the start of this year, there has been a significant rise in attacks targeting members of the Ismaili community, including killings and kidnappings, a stark escalation compared to 2025, when incidents against them were largely confined to theft and property damage.​​​​​​​​​​​​​​​​ Incidents Targeting the Ismaili Community in 2026: Haider Haider from Salamiyah killed in Homs on February 18, 2026, https://x.com/syjusticearc/status/2024161104721859030 Maad Nasser, 66 years old, killed in front of his house in Salamiyah on February 10, 2026 https://x.com/syjusticearc/status/2021267785347641793 Ismail Mustafa Safar from Salamiyah countryside was found dead in Homs countryside, March 14, 2026 https://x.com/syjusticearc/status/2032824907457761443 Ali Mustafa Al-Eizouqi, killed near Salamiyah on January 22, 2026 https://x.com/syjusticearc/status/2014970181064233072 Joseph Milad Zeino, young man in his twenties, kidnapped from a local store in Domar near Damascus on March 12, 2026. Kidnappers are demanding a huge ransom https://x.com/syjusticearc/status/2033538625447587862 Protest in Salamiyah denouncing killings,, and the lack of security in the city, on February 13, 2026 https://x.com/syjusticearc/status/2022310059288547639