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

Резултати

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

Пребарај: #aviationfuel

当前筛选 #aviationfuel清除筛选

የአውሮፓ ኅብረት የአውሮፕላን ነዳጅ እጥረት ለመቋቋም የሚያስችል ዕቅድ ይፋ ሊያደርግ ነው ************************** በመካከለኛው ምስራቅ አሜሪካ እና እስራኤል ከኢራን ጋር የገቡበት ጦርነት በአውሮፓ አየር መንገዶች ላይ የነዳጅ አቅርቦት እጥረት ስጋት ደቅኗል። ይህንን ችግር ለመቅረፍም የአውሮፓ ኅብረት ልዩ የመፍትሄ ዕቅድ እያዘጋጀ መሆኑን የህብረቱ ባለሥልጣናት መግለጻቸውን ሮይተርስ ዘግቧል። ኅብረቱ የነዳጅ ማጣሪያዎችን የማምረት አቅም ለማሳደግና የአቅርቦት ሰንሰለቱን ለማረጋጋት የሚያስችል ረቂቅ ሰነድ እያዘጋጀ ይገኛል። የአውሮፓ ኮሚሽን ከሚቀጥለው ወር ጀምሮ በአባል ሀገራቱ የሚገኙ የነዳጅ ማጣሪያዎችን የማምረት አቅም በዝርዝር የሚያጠና ሲሆን፣ ያሉትን ማጣሪያዎች ሙሉ በሙሉ ጥቅም ላይ እንዲውሉ የሚያስችሉ እርምጃዎችን ይወስዳል ተብሎ ይጠበቃል። አውሮፓውያን 75 በመቶ የአውሮፕላን ነዳጅ የሚያስመጡት ከመካከለኛው ምስራቅ በመሆኑ፣ ኅብረቱ አሁን ላይ የገጠመውን እጥረት ለመቅረፍ አማራጭ መፍትሄዎችን ለመመልከት ተገዷል። ዓለም አቀፉ የኢነርጂ ኤጀንሲ (IEA) በበኩሉ አውሮፓ ከመካከለኛው ምስራቅ የሚያገኘውን ነዳጅ ቢያንስ በግማሽ መተካት ካልቻለ፣ እስከ ሰኔ ወር ድረስ የክረምቱን የጉዞ ወቅት የሚያስተጓጉል ከፍተኛ እጥረት ሊያጋጥመው እንደሚችል ስጋቱን ገልጿል። በመሀመድ ፊጣሞ Ethiopian Broadcasting Corporation #Europe#AviationFuel#EnergyCrisis#IEA#EBC

Crypto M - Crypto News

@CryptoM · Post #64535 · 09.04.2026 г., 06:35

🚀 U.S. March CPI Expected to Rise Amid Ongoing Iran Conflict The market widely anticipates that the U.S. Consumer Price Index (CPI) for March will increase by 3.4%, surpassing last month's 2.4%, marking the largest year-on-year rise in two years. According to Jin10, during past oil market shocks, the most likely commodities to see price hikes include aviation fuel, steel, aluminum, natural gas, fertilizers, and plastics. Industries reliant on these materials are already feeling the strain. The ongoing Iran conflict, which has lasted several weeks, has shifted concerns from the initial oil price surge to the compounded effects of a prolonged conflict. For many economists, the most alarming aspect is not the immediate issues but the "aftershocks" that may emerge months or even years later. JPMorgan's CEO has referred to inflation as a potential "fly in the ointment" that could undermine stock market returns in 2026. Harvard University professor and former IMF chief economist Ken Rogoff recently discussed an overlooked impact of the war: the increased military spending's effect on the already strained U.S. budget deficit. He noted the risk of soaring bond yields, which could harm the stock market and affect U.S. affordability. Rogoff also mentioned that the current supply disruptions caused by the Iran conflict are sufficient to keep oil prices elevated for a year. #USCPI#inflation#IranConflict#oilprices#aviationfuel#steel#aluminum#naturalgas#fertilizers#plastics#economicimpact#stockmarket#JPMorgan#budgetdeficit#militaryspending#bondyields#HarvardEconomist#supplydisruptions#USaffordability