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

Пребарај: #rice

当前筛选 #rice清除筛选

📊Las clasificaciones de Ben Rice en 1B esta temporada: AVG: 1º (.330) HR: 2º (11) Carreras: T-1º (27) OBP: 1º (.444) SLG: 1º (.740) OPS: 1º (1.184) wRC+: 1º (216) fWAR: 1º (1.8) Rice está absolutamente arrasando 🍚 #Rice#Stats 🗞 | t.me/MLB_Daily

Hashtags

Amazing Geography 🌍

@amazingeo · Post #484 · 29.11.2025 г., 20:31

🌍 In China's southern hills, vast terraces transform mountains into rice fields. These hand-carved steps let farmers grow crops high above valleys, creating some of the world’s most scenic farmland. ✨ #agriculture⚡#landscapes⚡#rice⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #116 · 25.08.2025 г., 20:12

🌍 The ancient rice terraces of Banaue in the Philippines were built over 2,000 years ago. These stepped fields help prevent soil erosion and create new habitats for plants and animals. ✨ #rice⚡#terraces⚡#agriculture⚡#Philippines⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

GitHub Trends

@githubtrending · Post #15286 · 10.11.2025 г., 14:00

#qml#dotfiles#hyprland#linux#material_design#quickshell#rice#ricing#unixporn#wayland This Hyprland dotfiles setup gives you a modern, easy-to-use Linux desktop with features like a live app overview, AI integration (Gemini and Ollama), and automatic, beautiful color themes that match your wallpaper. Installation is simple with a one-line command, and the default keybinds are familiar if you’ve used Windows or GNOME. The system uses Quickshell for widgets (not Waybar), shows every command during setup for transparency, and offers a friendly Discord community for help. You benefit from a polished, customizable environment that’s both visually appealing and practical, with support for new users and advanced customization options. https://github.com/end-4/dots-hyprland