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

Резултати

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

Пребарај: #extinctanimals

当前筛选 #extinctanimals清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #1176 · 30.12.2025 г., 18:11

🌎 Australian megafauna like Diprotodon, the largest marsupial ever, disappeared about 46,000 years ago. These giant wombat relatives weighed up to 2,750 kilograms. The cause of their extinction is debated—some studies suggest climate shifts, while others blame human hunting. Diprotodon fossils have been found at over 100 sites across Australia. ✨ #extinctanimals⚡#megafauna⚡#paleontology 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1090 · 01.12.2025 г., 18:11

🌎 The mysterious extinction of the “Siberian unicorn,” or Elasmotherium sibiricum, puzzles paleontologists. This massive Ice Age mammal, related to modern rhinos, had a large forehead horn and grazed Eurasian steppes. DNA studies show it survived until about 39,000 years ago—much later than once thought. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #877 · 08.10.2025 г., 15:11

🌎 The woolly rhinoceros, Coelodonta antiquitatis, roamed Ice Age Eurasia with a thick fur coat and massive horn. Fossils found in Siberian permafrost show it survived extreme cold; its extinction about 14,000 years ago is linked to climate warming and human hunting. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #812 · 25.09.2025 г., 15:11

🌎 The giant short-faced bear, Arctodus simus, roamed North America during the last Ice Age. Standing up to 1.5 meters at the shoulder, it was one of the largest terrestrial mammalian carnivores ever, yet paleontologists debate if it was mainly a predator or a scavenger. Fossils suggest it vanished around 11,000 years ago, along with much other megafauna. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #715 · 09.09.2025 г., 03:22

🌎 The Siberian unicorn, or Elasmotherium, was a massive prehistoric rhinoceros with a single huge horn on its forehead. Fossils show it roamed Eurasia until about 39,000 years ago, much later than once believed. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #679 · 03.09.2025 г., 03:22

🌎 The thylacine, or Tasmanian tiger, was a striped marsupial predator native to Australia and Tasmania. Despite reports of sightings, the species was declared extinct in 1936 after the last known individual died in captivity. Intensive searches and camera traps have never produced concrete evidence of survival, but mystery sightings continue to spark debate among biologists. ✨ #extinctanimals⚡#marsupials⚡#australia 👉subscribe Interesting Planet ​