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

Резултати

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

Пребарај: #kurilovka

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

@druschbaFm_en · Post #51699 · 07.03.2025 г., 07:43

⚡️🇷🇺🇺🇦⚔️Fiend Reports in the Morning of 7 March 2025⚡️ 🔴#Kursk Region: 🔴In Sudzhansky district, in the area of #​​Sverdlikovo, Russian troops continue to attack with mobile groups along the border in southerly direction. 🟡 On the eastern flank, the RFAF have advanced into #Kurilovka and along the 'Kholodny Yar Ravine' to a depth of 4 kilometres. 🗺 Map 1 ➡️ The situation remains difficult (for the AFU). 🔴#Svatovo Front: 🔴 In #Kupyansk Sector, the Russians expanded the bridgehead on the western bank of the Oskol River in a section up to 2.73 kilometres wide and up to 1.15 kilometres deep. 🗺 Map 2 🔴#ChasovYar Direction: 🔴In #ChasovYar Sector, Russian troops, supported by 25 units of equipment, attacked the western part of the city. During the clashes, fighters of the AFU's 24th Brigade destroyed/hit 16 units of equipment and drove the Russians out of a number of positions. 🗺 Map 3 🎞 Video ➡️ A grey zone has been added to the map tentatively. The front configuration is being clarified. 🔴#Pokrovsk Direction: 🔴 On the right Flank, the AFU repelled attacks by Russian troops in the area of ​​#Peschanoye. 🔴 On the left Flank, the AFU repelled attacks by Russian troops in the area of ​​#Uspenovka and are also conducting counteractions in neighbouring areas. ➡️ The situation for the direction has not changed significantly. 📋Reported on 7 Mar at 08:00 📋Reported on 7 Mar at 08:18 📋Reported on 7 Mar at 08:31 🕰GMT+3; #smo 🇺🇦Map📍 📱For the Military Hardcore 💬 Welcome to Military Chat

DruschbaFM - English

@druschbaFm_en · Post #51663 · 06.03.2025 г., 07:32

⚡️🇷🇺🇺🇦⚔️Fiend Reports in the Morning of 6 March 2025⚡️ 🔴#Kursk Region: 🔴In Sudzhansky district, Russian troops continue attacks from the area of ​​the #NikolayevoDaryino settlement in the direction of #Sumy region, assaulting the area of ​​the #Lebedevka and #NovayaSorochina settlements. 🟡 At #Kurilovka, they have advanced in the eastern part of the 'Kholodny Yar Ravine' and on the southern outskirts of the settlement. 🗺 Map ➡️ The situation remains difficult (for the AFU). 🔴#Svatovo Front: 🔴 In #Kupyansk and #Liman directions, the situation has not changed significantly. 🔴#ChasovYar Direction: 🔴In #Toretsk Sector, fighting is taking place for the northern outskirts of the city and the southwestern part of the 'Zabalka Microdistrict.' The situation remains dynamic. 🔴#Pokrovsk Direction: 🔴 On the right Flank, fighting of varying intensity continues in the areas of ​​the #ZelyonoyePole, #Baranovka, #Shevchenko, #Peschanoye and #Kotlino villages... 🔴 On the left Flank, for #Udachnoye and #Uspenovka. 🔴#Komar Direction: 🔴In #Kurakhovo Sector, the RFAF reduced the number of attacks by infantry units and began to restore and accumulate forces and resources. 📋Reported on 6 Mar at 08:16 🕰GMT+3; #smo 🇺🇦Map📍 📱For the Military Hardcore 💬 Welcome to Military Chat