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

Резултати

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

Пребарај: #dariadugina

当前筛选 #dariadugina清除筛选
BadVolf

@BadvolfNews · Post #260 · 22.08.2022 г., 15:00

From Alexander Dugin: “As you all know, as a result of a terrorist attack carried out by the Nazi Ukrainian regime, on August 20, while returning from the Tradition festival near Moscow, my daughter Daria Dugina was brutally killed by an explosion in front of my eyes. She was a beautiful Orthodox girl, a patriot, a military correspondent, an expert on the central channels, and a philosopher. Her speeches and reporting have always been profound, grounded and restrained. She never called for violence and war. She was a rising star at the beginning of her journey. The enemies of Russia meanly, stealthily killed her ... But we, our people, cannot be broken even by such unbearable blows. They wanted to crush our will with bloody terror against the best and most vulnerable of us. But they won't get it. Our hearts yearn for more than just revenge or retribution. It's too petty, not Russian. We only need our Victory. My daughter laid her maiden life on her altar. So win, please! We wanted to raise her to be smart and a hero. Let it inspire the sons of our Fatherland to the feat even now. Farewell to Daria Dugina (Platonova) - a civil memorial service - will take place on August 23 at the Ostankino Television Center at 10 am. Alexander Dugin #ECM#DariaDugina

Sos Donbass

@sos_donbass · Post #688 · 23.08.2023 г., 06:28

Un verset du journal de Darya Dugina, qu'elle a tenu pendant les trois dernières années de sa vie. Certaines de ses citations sont utilisées dans le livre, qui est publié à titre posthume « Marais et hauteurs de mon cœur. Journal" : Partir à l'heure et tranquillement, Sans douleur intense et cris forts, Aucune offense et aucun regret Mots vides et doutes. Partir doucement et calmement : Fermer les yeux pour rester un guerrier, Ayant réussi à voir ses proches… Pardonnez-moi, je dois partir. #dariadougina#poemes#dariadugina

Sos Donbass

@sos_donbass · Post #1296 · 19.08.2024 г., 16:26

🗣️ Nouvelles de SOS DONBASS, prononcées par le président de l’association Vincent Perfetti: ▫️ Compte bancaire / reprise de l’activité ▫️Action LA RUSSIE N’EST PAS MON ENNEMI ▫️ Commémoration de Daria Douguina ▫️ Aide à la population de Koursk #dariadouguina#dariadugina#sosdonbass#donbass#russie#ukraine#solidarite