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

Резултати

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

Пребарај: #digestion

当前筛选 #digestion清除筛选
STAR VET BOOKS

@starvetbooks · Post #4351 · 06.08.2024 г., 05:17

🐄🐄 𝘿𝙄𝙂𝙀𝙎𝙏𝙄𝙊𝙉 𝙄𝙉 🐄𝙍𝙐𝙈𝙄𝙉𝘼𝙉𝙏𝙎 🐄🐮 👉All herbivores (plant-eating mammals) are called ruminants. 👉They rechew the cud to break down plant matter and stimulate digestion. 👉The stomach is divided into four chambers- rumen, reticulum, omasum, and abomasum. 🐄🐮 𝙋𝙧𝙤𝙘𝙚𝙨𝙨 𝙊𝙛 𝘿𝙞𝙜𝙚𝙨𝙩𝙞𝙤𝙣 🐄🐮 👉Ruminants quickly swallow the food and store it in the rumen. 👉Once the rumen is filled, food is passed into the second chamber (reticulum). 👉In the reticulum, digestive juices partially digest the food. 👉Partially digested food is called cud. 👉Now when mammals are resting, bring the cud back into the mouth for rechewing. 👉After cud is chewed food is passed to the omasum and the abomasum. 👉Symbiotic bacteria in the caecum brought complete digestion of cellulose. #digestion https://t.me/starvetbooks

Hashtags

FenSloshes 🔞

@FenSloshes · Post #29 · 12.01.2020 г., 20:30

That's Better~ - #animation#soft#digestion 🎨https://www.furaffinity.net/gallery/elricmysteryshifter/ 🎥https://www.furaffinity.net/view/32597334/ 🎧https://www.furaffinity.net/view/34580255/

FenSloshes 🔞

@FenSloshes · Post #28 · 12.01.2020 г., 14:44

Espeon Wins (Internal) - #animation#soft#digestion 🎨https://www.furaffinity.net/gallery/elricmysteryshifter/ 🎥https://www.furaffinity.net/view/33080976/ 🎧https://www.furaffinity.net/view/34576234/

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