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

Резултати

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

Пребарај: #triton

当前筛选 #triton清除筛选
Universe Mysteries 🪐

@cosmomyst · Post #5 · 29.07.2025 г., 14:43

🌎 On Neptune’s largest moon Triton, geysers of nitrogen ice erupt from beneath the surface, shooting plumes up to 8 kilometers high into the tenuous atmosphere. These cryovolcanic eruptions are driven by sunlight warming a thin layer of transparent ice, a unique phenomenon that shapes Triton's mysterious, dark-streaked terrain. ✨ #Triton⚡#cryovolcanism⚡#Neptune 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #28 · 30.07.2025 г., 02:51

🪐 On Triton, Neptune's largest moon, icy volcanoes known as cryovolcanoes have been observed erupting plumes of nitrogen gas many kilometers high. This frigid world’s surface is scattered with dark streaks—evidence of these geysers venting from below, hinting at surprising geologic activity beneath its frozen crust. ✨ #Triton⚡#cryovolcanoes⚡#Neptune 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #21 · 29.07.2025 г., 23:00

🪐 On Neptune’s moon Triton, geysers erupt through its icy crust, blasting nitrogen gas more than 8 kilometers above the surface. These plumes create dark streaks and ever-changing patterns on Triton's frozen landscape, transforming the distant moon into one of the most dynamic worlds in the outer solar system. ✨ #Triton⚡#geysers⚡#Neptune 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #109 · 10.08.2025 г., 03:11

🪐 Within our solar system, scientists have discovered that the subsurface ocean of Neptune’s moon, Triton, could provide the right conditions for life despite its bitterly cold surface. Tidal forces, or gravitational stretching from Neptune, may keep this hidden ocean liquid beneath Triton’s icy shell, making it a fascinating target in the ongoing search for places where life could exist beyond Earth. ✨ #Triton⚡#ocean⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #701 · 04.03.2026 г., 22:21

🪐 Neptune’s largest moon, Triton, is thought to conceal a hidden ocean beneath its frozen exterior, thanks to heat generated by radioactive decay in its rocky core. Despite surface temperatures near minus 235°C, this internal heat may keep water liquid deep inside, making Triton one of the most intriguing ocean worlds in the outer solar system. ✨ #Triton⚡#oceanwonder⚡#Neptune⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​