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

Пребарај: #chirp

当前筛选 #chirp清除筛选
🦅 [ perspective ix ]

@perspectiveix · Post #1359 · 26.06.2018 г., 12:00

📰#iXDailyBrief STAT ⚡️ The leading activity in apps is digital audio, with the average US adult listening to over 50 minutes of audio via mobile apps per day. Social networking is next, with 40 minutes of app time. The other major categories are mobile video, gaming and messaging. Of these five, gaming is growing most slowly. (Source: eMarketer) INSIGHT 📺 How brands are using #Instagram’s new long-form video feature, #IGTV: prs.pctvix.co/2yPgJAC OTHER NEWS 🇻🇪 Venezuela is blocking access to the Tor network: t.me/iXNews/28209 📱#iOS12 is all about making your phone work better (Public Beta Available Now): t.me/iXNews/28205 💰#VidCon’s new grant will award one emerging YouTuber $2,000 each week for a year: t.me/iXNews/28186 🐦#Twitter returns to #AppleWatch thanks to #Chirp: t.me/iXNews/28182 🇨🇳 John Oliver is erased from Chinese internet following segment on China: t.me/iXNews/28183 — ☕️ If you like our channel, please support us: prs.pctvix.co/2taiWBz — "Success is no accident. It is hard work, perseverance, learning, studying, sacrifice and most of all, love of what you are doing or learning to do." ― Pele Ben, @iXNews

GitHub Trends

@githubtrending · Post #15270 · 05.11.2025 г., 12:00

#jupyter_notebook#chirp#gemini#google_cloud#imagen#lyria#nano_banana#veo#vertex_ai GenMedia Creative Studio is a web app that lets you use Google Cloud’s generative AI tools to create images, videos, music, and speech. It includes features like Imagen for images, Veo for videos, Lyria for music, and Chirp for speech, plus creative workflows for tasks like virtual try-ons and moodboards. You can experiment with these tools to quickly make and test creative media, helping you bring new ideas to life faster and more easily. https://github.com/GoogleCloudPlatform/vertex-ai-creative-studio