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

Резултати

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

Пребарај: #tendencias

当前筛选 #tendencias清除筛选
producTICvidad® 📲📈

@producTICvidad · Post #910 · 04.10.2022 г., 00:02

#tendencias#trends La FIFA aprobó el uso de balones especiales con sensores incorporados. Con dicho sensor será más fácil determinar el fuera de juego, porque el sistema se activará al instante. FIFA approved the use of special balls with built-in sensors. With such a sensor it will be easier to determine offside, because the system will be triggered instantly. F/ FIFA La productividad está en tiC 📲📈

producTICvidad® 📲📈

@producTICvidad · Post #966 · 13.01.2023 г., 02:31

OpenAI BOT A chat bot that uses OpenAi to process questions and statements. Created by @OpenAIERC | $OPENAI #tendencias#tecnologías OpenAIChat. Por favor, pregúntale cualquier duda que tengas a esta inteligencia artificial que vive dentro de tu Telegram. Y si quieres saber su calidad humana cibernética... pregúntale qué opina de lo que sea. 💡💡 Para preguntar solo tienes que escribirle: /ask aquí-tu-pregunta https://t.me/openaichat_bot

producTICvidad® 📲📈

@producTICvidad · Post #961 · 04.01.2023 г., 00:38

Bienvenido al 2035 / Welcome to 2035🎉 Empezamos año con una bienvenida al 2035. La siguiente herramienta de visualización interactiva, realizada por WKO, muestra 105 tecnologías emergentes que se espera que impacten a las principales industrias para 2035. Estas #tecnologías se agruparon en 5 #tendencias, revelando las principales interacciones entre la sociedad, las empresas y estas herramientas tecnológicas. Te invito a navegar por esta poderosa herramienta, descubrir el mundo del mañana y sus posibilidades comerciales. Si tienes alguna herramienta de análisis de entorno me gustaría que la compartas... Hecho con 💚por producTICvidad® https://radar.envisioning.io/wko/innovation/?pg=welcome

producTICvidad® 📲📈

@producTICvidad · Post #980 · 30.01.2023 г., 17:13

Mapa de profesiones más deseadas en todo el mundo #tendencias#talentohumano#producTICvidad Los datos de búsqueda de Google se utilizaron para establecer el volumen de búsqueda anual (octubre de 2021 a octubre de 2022) en cada país para los términos de búsqueda "cómo ser un [trabajo]" asociados con soñar con un nuevo trabajo o carrera para cada país en el mundo. El trabajo más buscado se usó como la mejor carrera para el país específico. ¿Qué opinas de Suramérica? Datos consolidados a noviembre de 2022.

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