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

Резултати

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

Пребарај: #cloverproject

当前筛选 #cloverproject清除筛选
Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #675 · 20.09.2025 г., 17:08

The Clover Project - Official | Android 16 | Nothing Phone (2) 📝 Details: - Version: v3.2 - Device: #Pong - Released: 20/09/25 ⬇️ Download: Here 🎥 Screenshots : Here ⚙️ Flashing Instructions: Here 📖 Changelogs: Source | Device 🆘 Support : Here 💰 Donate: Ko-fi | Paypal 🏷 Tags: #AOSP#ROM#CloverProject#Official ✍️Notes: - Use latest NOS 3 firmware - Dolby is included 🏆Credits: - Chandu for base DT - Ghost for Dolby and additional fixes - Fabian & HELLBOY for Glyph - HELLBOY for Meteoric Kernel 👤 Maintainer: @Superuser1958 🔔 Updates: @NothingPhone2Updates 💬 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #664 · 19.08.2025 г., 23:58

The Clover Project - Official | Android 16 | Nothing Phone (2) 📝 Details: - Version: v3.1 - Device: #Pong - Released: 18/08/25 ⬇️ Download: Here 🎥 Screenshots : Here ⚙️ Flashing Instructions: Here 📖 Changelogs: Source | Device 🆘 Support : Here 💰 Donate: Ko-fi | Paypal 🏷 Tags: #AOSP#ROM#CloverProject#Official ✍️Notes: - Use latest NOS 3.0 firmware - Dolby is included 🏆Credits: - Chandu for base DT - Ghost for Dolby and additional fixes - Fabian & HELLBOY for Glyph - HELLBOY for Meteoric Kernel 👤 Maintainer: @Superuser1958 🔔 Updates: @NothingPhone2Updates 💬 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #640 · 24.06.2025 г., 09:24

The Clover Project - Official | Android 15 | Nothing Phone (2) 📝 Details: - Version: v2.7 - Device: #Pong - Released: 24/06/25 ⬇️ Download: Here | Mirror 🎥 Screenshots : Here ⚙️ Flashing Instructions: Here 📖 Changelogs: Source | Device 🆘 Support : Here 🏷 Tags: #AOSP#ROM#QPR2#CloverProject#Official ✍️Notes: - Use latest NOS 3.0 firmware - Dolby is included 🏆Credits: - Chandu for base DT - Ghost for Dolby and additional fixes - Fabian & HELLBOY for Glyph - HELLBOY for Meteoric Kernel 👤 Maintainer: @Superuser1958 🔔 Updates: @NothingPhone2Updates 🐙 Chat: @NothingPhone2

Nothing Phone (2) | Updates

@NothingPhone2Updates · Post #571 · 02.03.2025 г., 06:10

The Clover Project - Official | Android 15 | Nothing Phone (2) 📝 Details: - Version: v2.3 - Device: #Pong - Released: 02/03/25 ⬇️ Download: Here 🎥 Screenshots : Here ⚙️ Flashing Instructions: Here 📖 Changelogs: Source | Device 🆘 Support : Here 🏷 Tags: #AOSP#ROM#QPR1#CloverProject#Official ✍️Notes: - Firmware is included - Dolby is included 🏆Credits: - Chandu for base DT - Ghost for Dolby and additional fixes - Fabian & HELLBOY for Glyph - HELLBOY for Meteoric Kernel 👤 Maintainer: @Superuser1958 🐙 Chat: @NothingPhone2 🔔 Updates: @NothingPhone2Updates