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

Пребарај: #cheremoshnoye

当前筛选 #cheremoshnoye清除筛选
DruschbaFM - English

@druschbaFm_en · Post #52510 · 25.03.2025 г., 08:03

⚡️ 🇷🇺 🇺🇦⚔️ Ukraine Fronts on the Morning of 25 March⚡️ 🔴#Sumy Direction: 🔴In #Sudzha Sector, to the west on Ukrainian lands, for the claimed RFAF entry into #Vladimirovka is still confirmation or other proof missing (so, the black arrow on map turned blue). 🟡 At #Veselovka, the RFAF crossed the border and entered the settlement (1st black arrow). 🟡 For #Zhuravka, the battle continues. 🟡 In #Basovka, as well. 🟡#Novenkoye, is under safe RFAF control (1st red arrow). 🟡 In #Kursk region, according to unconfirmed reports, the RFAF took the 'Sudza Gas Transmission Point' and a battle for the checkpoint is taking place (4th black arrow). 📌 If true and the RFAF wins, a cauldron could form. 🟡#Gogolevka is likely still under AFU full control (2nd blue arrow). 🟡 In #Melovoy, the battle likely continues (5th black arrow). 🟡#Oleshnya, #Guyevo and #Gornal remain under AFU control for now (4 large blue arrows on map). 🔴 In #KrasnayaYaruga Sector, the AFU tried to take #Popovka (6th black arrow) to outflank the embattled #Demidovka (7th black arrow). In the course of the battle, Russian border guards defeated AFU special forces and got later on evacuated by reinforcement. The battle for both villages continue. The situation is dynamic. Further AFU action is likely. 🟡#Grafovka, remains under RFAF control. 🟡#Prilesye as well. 🗺 All on Map 1 🔴 In #Kharkov Direction, on #Svatovo Front, in #ChasovYar and #Kherson Directions, the battles continued without major changes. 🔴#Pokrovsk Direction: 🔴 On the right Flank, far east, the RFAF took #Aleksandropol and entered #Panteleymonovka's southeastern part north of it. Reportedly the latter has also been taken (unconfirmed). The assaults are towards #Toretsk in the north. 🟡 From #ZelenoyePole, further west, the RFAF advanced (unconfirmed) ca. 600 m towards #Aleksandropol2nd. 🟡 In #Tarasovka, reportedly there was also a Russian progress. 🔴 South of the City, fierce fighting is taking place. 🟡 For #Shevchenko, the battle continues in its northeastern part. 🟡#Peschanoye came under RFAF control (unconfirmed). 🟡#Kotlino as well. 🔴 On the left Flank, north of #Udachnoye, the RFAF are assaulting the mine. 🟡 In #Udachnoye, Russian troops consolidated in the eastern settlement part. 🟡 In #Solyonoye, to the south, the AFU have entered the western part of the settlement. 🔴#Komar Direction: 🔴In #Konstantinopol Sector, the battles continued. 🔴 In #Komar Sector, the RFAF have advanced towards the settlement of #VolnoyePole and entered its eastern outskirts. 🔴#Zaporozhye Direction: 🔴For the #Orekhov Section, we are forced to correct the situation based on confirmed data and video evidence. 🟡#Shcherbaki is likely completely AFU controlled. 🟡 Nearby #MalyeShcherbakito the west continues to be contested. The RFAF hold positions in the south of the village. 🟡#Stepovoye's alleged takeover did not take place. The Russians have entered the village several days ago. Heavy fights are ongoing. 🗺 Map 2 🎬 Video 1 🟡#Lobkovoye to the south is contested. The current situation is unclear. The Russians have at best entered its southeastern edge. 🟡 For #​​Pyatikhatki's alleged takeover, confirmation or video evidence is still missing. The AFU is likely still present in the western part of the village. 💥#OldRussia: 🔵In #Belgorod Region, the AFU targeted the civilian population in #Shebekino town and in the villages of #YasnyeZori and #Cheremoshnoye. In the area of #Mikhaylovka (#LPR), the AFU killed 6 people, 3 among them journalists, in a double HIMARS strike. 💥#RestUkraine: 🔵 On #Kiev,#Poltava and #Izyum regions, the RFAF carried out strikes. In #Sumy region, a missile has hit militants and equipment in the residential area. 🎬 Video 2 🎞 Vids Source 1; Source 2; 🗺 Maps @olegtsarov; @creamy_caprice 📋 Sources: CC; Tsarov; ⚡️2M; 🇺🇦Fiend;😼Kotenok 🕰As of 25 Mar 2025; 06:32 GMT+3;📃24 Mar 📱 Join GLOBAL DEPTH to boost your TG Feed 💬Join Military Chat for Comments & Discussions 🇺🇦On Ukraine Observer you will find your daily independent Ukraine War Battle Update