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

Резултати

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

Пребарај: #freepalestine

当前筛选 #freepalestine清除筛选
Yulduz Usmonova

@Yulduz_Usmonova · Post #3631 · 08.01.2025 г., 19:26

#FreePalestine Yulduz Usmonova va Mansur Agaliev tomonidan Falastindan olib kelingan ayollar va bolalarga "Shohsaroy" uylaridan 2 ta kvartira sovg'a qilindi. @Yulduz_Usmonova @YulduzIbragimovnaUsmonova

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3497 · 19.10.2024 г., 17:21

The baton he cast never touched the ground; before it could fall, it was seized by those prepared to continue the path towards Liberation. Palestine remains resilient and unwavering, ever-ready to nurture countless successors like Sinwar, ensuring the struggle endures. #FreePalestine

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3483 · 18.10.2024 г., 03:41

Martyr Yehya Sinwar faced his final moments with unwavering defiance. Clad in his fatigues, even with his right arm severed, he mustered the strength to hurl a stick at the Israeli drone recording him, a gesture of defiance in the face of overwhelming odds. From the moment he initiated the Al Aqsa Flood, he had accepted his fate with unyielding resolve. This footage serves as a potent symbol, one that will undoubtedly fuel the momentum of the rising tide. #FreePalestine

Unicorn Riot

@unicornriotninja · Post #3435 · 07.08.2025 г., 14:17

Denver, CO: #FreePalestine Sit-In Protests Zionist Ties at Center on Colfax - 2/2 [Twitter Archive, August 6, 2024]: https://unicornriot.ninja/2024/pro-palestine-anti-genocide-activists-rally-outside-denver-community-center-with-ties-to-israel/

Unicorn Riot

@unicornriotninja · Post #3434 · 07.08.2025 г., 14:17

Denver, CO: #FreePalestine Sit-In Protests Zionist Ties at Center on Colfax - 1/2 [Twitter Archive, August 6, 2024]: https://unicornriot.ninja/2024/pro-palestine-anti-genocide-activists-rally-outside-denver-community-center-with-ties-to-israel/

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3202 · 13.09.2024 г., 20:23

📍Location: Meron Mountain, northern occupied Palestine. 🔻Hezbollah Rockets rain on illegal colonial settlers after Israel killed civilians in south Lebanon hours before. Result: You reap what you sow. This is what haopens to you when you are land thieves. Leave. Now. #FreePalestine

Эртай Искаков

@ertaisfr · Post #1721 · 27.10.2023 г., 10:14

Мусульмандардын каны төгүлгөн үчүн адам укугу деп дүйнөдө кыйкыргандар унчукпай отурушат. Эртең 28-ноябрь саат 11:00 Бишкекте Горький паркында Палестина элин колдоо акциясы өтөт. Исанова менен Рыскулова кесилишинде. Акция учурунда гумжардам чогултулат. #freepalestine

123•••910
ПретходнаСтраница 1 од 10Следна