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

Резултати

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

Пребарај: #pulkovo

当前筛选 #pulkovo清除筛选
International News

@intnewsagency · Post #9334 · 17.04.2026 г., 05:23

Key Update at 08:00: International Agenda and Security Pulkovo airport halts flights due to a drone attack, highlighting rising regional security threats. Russian drones strike Ukrainian targets amid ongoing special operations. The US delays arms deliveries to Europe, focusing on tensions with Iran. A major success: the launch of the Soyuz-2.1b rocket from Plesetsk carrying military satellites, boosting national defense. “Security remains a priority in challenging times.” #Russia#Security#InternationalNews#Pulkovo#SpecialOperation The main news of Russia and the world ishere.

International News

@intnewsagency · Post #8801 · 22.03.2026 г., 16:40

Pulkovo Airport Resumes Normal Operations Pulkovo Airport in Saint Petersburg has fully returned to regular operations after temporary restrictions. According to @interfaxonline, all flights are now operating on schedule, ensuring reliable connections between the city, other Russian regions, and international destinations. The airport’s restored functioning supports the normalization of transport infrastructure and boosts the region’s business activity. #Pulkovo#aviation#SaintPetersburg#transport#news The main news of Russia and the world ishere.

dopingpong

@dopingram · Post #2554 · 02.07.2023 г., 09:10

«Детская любовь к самолетам», 70х100см, холст, масло, Doping Pong, 2023 Аукцион VLADEY RUSSIA Живые торги в зале! Участие онлайн и по телефону Трансляция на сайте 4 июля в 20:00 Предаукционная выставка: 23 июня — 4 июля C 11:00 До 22:00, без выходных VLADEY Неглинная, 14 стр. 1А, вход 4 More info: Лот 62 https://vladey.net/ru/lot/10768 #dopingpong#ussr#retro#aeroflot#childhood#love#airplane#pulkovo#oiloncanvas