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

Резултати

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

Пребарај: #jet

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

@cosmomyst · Post #49 · 31.07.2025 г., 00:11

🪐 The massive elliptical galaxy Messier 87 in the Virgo Cluster possesses a jet of energetic plasma that extends for nearly 5,000 light-years from its supermassive black hole. This powerful jet glows fiercely in visible and X-ray light, fueled by material swirling toward the event horizon and launched at nearly the speed of light into intergalactic space. ✨ #M87⚡#blackhole⚡#jet⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries

TOP Signals Spot

@cryptocurreniesbtc · Post #23033 · 09.08.2024 г., 16:28

Hello everyone, 48 hours left until our next free for all pump on MEXC!! The target this time will be 50X-100X gains possibly even more. B Bulls took a stand at the $50k support sparking an immediate and powerful rebound. The market now roars with bullish energy, and momentum is very strong indicating alts monster rally ahead so We can guarantee that this upcoming mega pump will have amazing results like our previous pumps: #YOLO (3200%) #VTS (3500%) #FRTN (6500%) #JET (+10600%) We are pumping on MEXC because MEXC is the best place to profit from small cap gems. There are a lot of trading pairs listed which allow us a breadth of options. Many retail, algo, and daily active traders use MEXC and will add additional volume to our signals and we believe that with our massive buying power we will be able to reach 50X-100X easily possibly even more as there is very little hidden sell pressure in the orderbooks. This event will be the biggest one that we have done in the history of our group and will top our previous ones in terms of % gain. we’re ready to see our biggest volume in history, Be prepared for a massive 50X-100X pump signal on MEXC this Sunday.

Mexc Crypto Signals Pumps Trading Kucoin

@mexc_signals_pumps_trading · Post #1267 · 09.08.2024 г., 17:19

Hello everyone, 47 hours left until our next free for all pump on MEXC!! The target this time will be 50X-100X gains possibly even more. Bulls took a stand at the $50k support sparking an immediate and powerful rebound. The market now roars with bullish energy, and momentum is very strong indicating alts monster rally ahead so We can guarantee that this upcoming mega pump will have amazing results like our previous pumps: #YOLO (3200%) #VTS (3500%) #FRTN (6500%) #JET (+10600%) We are pumping on MEXC because MEXC is the best place to profit from small cap gems. There are a lot of trading pairs listed which allow us a breadth of options. Many retail, algo, and daily active traders use MEXC and will add additional volume to our signals and we believe that with our massive buying power we will be able to reach 50X-100X easily possibly even more as there is very little hidden sell pressure in the orderbooks. This event will be the biggest one that we have done in the history of our group and will top our previous ones in terms of % gain. we’re ready to see our biggest volume in history, Be prepared for a massive 50X-100X pump signal on MEXC this Sunday.