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

Резултати

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

Пребарај: #slang

当前筛选 #slang清除筛选
English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #59908 · 23.07.2025 г., 06:16

#Slang 💥Be a hundred years too early •To be so immature and unprepared as to have no hope of achieving an accomplishment. ●Example: ⚡️Don't make me waste my time! You are a hundred years too early to be an opponent worthy of fighting me!

Hashtags

English From Zero to Hero

@Learn_English_from_Zero_to_Hero · Post #59733 · 11.05.2025 г., 11:34

#Slang ⚜All good in the hood <Interjection> ▪️ Everything is all right; no problem; used to reassure someone. ▪️"Sorry about nearly breaking your vase, Carl." "I don't mind, man. All good in the hood."

Hashtags

English Universe

@englishuniverseschool · Post #3 · 04.12.2025 г., 14:27

Рубрика ‘слово дня’ И первопроходцем будет слово ‘SLAY’ 😎 /sleɪ/ 1️⃣to impress someone very much or to be very good or impressive 2️⃣to be extremely good or nice Examples: The actors slay me with the quality of their acting. That top slaaaays! Перевод: крутой, впечатляющий (впечатлить) #slang

Hashtags

1 English learning materials

@englishmeta1 · Post #187 · 01.10.2022 г., 15:21

Bling 🏅 Meaning flashy jewellery worn to create the impression of wealth ❕For example 🔺Check out all the bling around that guy's neck. It must weigh a ton! 🔺Most people have gold bling or silver bling, but they don't usually mix it up. ✍Note "bling-bling" means the same thing 🌟Origin Originally used in U.S. hip-hop and rap culture, and possibly derived from the sound of heavy necklaces hitting one another. ✨Variety This slang term is typically used in American English but may be used in other varieties of English too. ━━━━━━━━━━━━━ #teamjimmy #sirjimmy #slang

1 English learning materials

@englishmeta1 · Post #26 · 08.02.2022 г., 05:00

Slang ✅ Peacocking ✨ Meaning Showing off Peacocking is when a person shows off to impress someone. It comes from the colorful feathers an actual peacock displays to attract a mate. The term is commonly used in regards to dating when a male tries to impress a female by doing something flashy to stand out from among the rest of the suitors. Peacocking may take the form of driving a really expensive car, learning some sweet dance moves, or domming in sports. 🗣 Example 🔸 "James is peacocking on the dance floor in order to get a dance with one of the bridesmaids. 🔸 Gaston peacocking with his chest muscle s ══❖•🌺🌸•❖══ #Slang #Teamjimmy #sirjimmy

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