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

Резултати

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

Пребарај: #autostocks

当前筛选 #autostocks清除筛选
Crypto M - Crypto News

@CryptoM · Post #64523 · 09.04.2026 г., 06:03

🚀 STOCKS | Hong Kong Auto Stocks Decline in Afternoon Trading Hong Kong's auto stocks experienced a downturn in afternoon trading. According to Jin10, XPeng Inc. (09868.HK) saw a decline of over 5%, while BYD Company Limited (01211.HK) dropped more than 4%. Other companies such as Seres Group (09927.HK) and Li Auto Inc. (02015.HK) also followed the downward trend. #HongKong#AutoStocks#XPeng#BYD#SeresGroup#LiAuto#StockMarket

Crypto M - Crypto News

@CryptoM · Post #64479 · 09.04.2026 г., 02:07

🚀 STOCKS | Hong Kong Auto Stocks Surge with Geely and Chery Leading Gains Hong Kong's automotive stocks have shown significant strength, with notable gains observed in several key companies. According to Jin10, Geely Automobile Holdings Limited (00175.HK) and Chery Automobile Co., Ltd. (09973.HK) both experienced increases of over 4%. Additionally, NIO Inc. - SW (09866.HK) saw a rise of more than 3%, while Leapmotor (09863.HK) also followed the upward trend. This surge reflects a positive sentiment in the Hong Kong auto market, driven by investor confidence and market dynamics. #HongKong#AutoStocks#Geely#Chery#NIO#Leapmotor#Automotive#StockMarket#InvestorSentiment