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

Резултати

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

Пребарај: #dictation

当前筛选 #dictation清除筛选

Дорогие друзья! 📚 Русский дом в Нью-Дели приглашает вас принять участие в международной исторической акции «Диктант Победы». 📆 Ждем Вас 24 апреля в 12:00. 🔗 Язык диктанта - русский и английский. 🏢 Место проведения: Русский дом в Нью-Дели. 📍Адрес: 24, Фироз Шах Роуд, г. Нью-Дели. ✅ Вход для посетителей мероприятия - свободный. 🔗При себе необходимо обязательно иметь ID-карту (на бумажном носителе). 💎 Не упустите возможность стать частью важного события! Ждем Вас! #РусскийДом#Диктант#Индия Dear friends! 📚 The Russian House in New Delhi invites you to participate in the international historical campaign "Victory Dictation." 📆 We look forward to seeing you on April 24 at 12:00 p.m. 🔗 The language of the dictation is Russian and English. 🏢 Venue: Russian House in New Delhi. 📍Address: 24, Firoz Shah Road, New Delhi. ✅ Entrance for visitors to the dictation is free. 💎 Don't miss the opportunity to become part of an important event! We are waiting for you! #RussianHouse#Dictation#India

Libreware

@libreware · Post #1477 · 07.08.2025 г., 03:49

WhisperTux Simple #voice#dictation application for #Linux. Uses whisper.cpp for offline speech-to-text transcription. No fancy GPUs are required although whisper.cpp is capable of using them if available. Once your speech is transcribed, it is sent to a ydotool daemon that will write the text into the focused application. Features Local speech-to-text processing via whisper.cpp (no cloud dependencies) No expensive hardware required (works well on a plain x86 laptop with AVX instructions) Global keyboard shortcuts for system-wide operation Automatic text injection into focused applications Configurable whisper models and shortcuts https://github.com/cjams/whispertux #assistant#speech#stt