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

Резултати

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

Пребарај: #terminal

当前筛选 #terminal清除筛选
Libreware

@libreware · Post #1413 · 14.02.2025 г., 17:47

kitty The fast, feature-rich, GPU based #terminal emulator Uses GPU and SIMD vector CPU instructions for best in class Uses threaded rendering for absolutely minimal latency Performance tradeoffs can be tuned Capable Scriptable Composable Cross-platform Innovative To get started see Quickstart. https://sw.kovidgoyal.net/kitty/ With software, such as "Kitty", it is possible to read documents, images and other graphical formats with these software: https://github.com/dsanson/termpdf.py http://www.kraxel.org/blog/linux/fbida/ https://github.com/itsjunetime/tdf It means, that we no longer need GTK+ (which dropped support for X11), Qt and other graphical toolkits in order to have a full operational computer.

Hashtags

sudo recast

@sudo_recast · Post #204 · 23.05.2022 г., 17:51

Warp 從上個月開始面向林檎電腦用戶公測。很快,很現代智慧,雖然搶佔掉了許多原來的 shell 設定。UI 很精緻。 #terminal

Hashtags

The Devs

@thedevs · Post #1734 · 01.05.2020 г., 18:28

qrcp, transfer files over wifi from your computer to your mobile device by scanning a QR code without leaving the terminal. #tools#terminal @thedevs https://kutt.it/fycGgm

The Devs

@thedevs · Post #1325 · 08.12.2018 г., 14:49

eDEX-UI, a science fiction terminal emulator designed for large touchscreens that runs on all major OSs. #tools#terminal @thedevs https://kutt.it/IaR1au

ПретходнаСтраница 1 од 5Следна