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

Пребарај: #animalrescue

当前筛选 #animalrescue清除筛选
EKOLOG.UZ| ENG

@ekologuzenglish · Post #10112 · 28.10.2025 г., 05:02

💔Every abandoned animal is a little soul searching for love… On the streets of our cities, thousands of homeless cats and dogs face cold, hunger, and loneliness every day. They don’t ask for much—just a little warmth, care, and understanding. Yet often, their world is concrete sidewalks and dangerous roads. 🐾Those eyes, full of hope, can change your day. Each of them deserves a chance at a home, a family, and love. Sometimes one hug, one bowl of food, or just a minute of attention can save a life. 🙏Be kind. Adopt. Support. Donate food. Tell your friends about shelters. Remember: saving one animal changes an entire world—even if it’s a small one, it matters. 💖Let’s not be indifferent. Every animal deserves a chance at happiness. #HomelessAnimals#AnimalRescue#Kindness#SaveALife

STAR VET BOOKS

@starvetbooks · Post #4967 · 22.02.2025 г., 07:01

On Sunday, February 23, 2025, we will be holding a blood donation, dog adoption, and fundraising program in collaboration with Ahadu Rotaract Club at the Red Cross compound around Addis Ababa Stadium starting 9AM To those who want to donate: - Food (Rice) for feeding purpose - Pet beds - Comfy blankets - Medications - Pet toys - Dry pet foods - pet accessaries We will gladly be waiting, the program will be held until 5pm. Come, save lives by donating blood, create a family by adopting dogs! #BloodDonation#DogAdoption#CommunityService#AddisAbaba#Ethiopia#SaveLives#GiveBack#AnimalRescue#Rotaract#AhaduRotaract#Fundraising#CharityEvent https://t.me/starvetbooks