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 слични објави

Пребарај: #privatesale

当前筛选 #privatesale清除筛选

🎙 SEASIDE CLUB announcing Seed Sale phase on December 🔥🔥🔥 📌 Seaside Club is an international holding company that comprises different business endeavors around the globe that has developed an innovative investment mechanism for retail and corporate investors. 📌 The core of the mechanism relies on the blockchain technology via a unique smart contract system, Seaside Coin and proof-of-ownership NFTs. 📌 Company deals with real estate, ore mining, agricultural production, motion picture industry, retail apparel and with a rage of digital projects including their own NFT marketplace and Metaverse. 💎 Seaside Coin 💎 The core of the Seaside Ecosystem! Unique coin that is backed by the real world businesses that are digitized via a special smart contract structure! 💎 Seaside Business Ecosystem 💎 A unique investment system that allows you to earn fixed 30% yearly returns on your total value locked in staking! Convenient, profitable and safe from volatility investment system that welcomes anyone! 💎 Own Branded TV Series 💎 In order to boost the global brand recognition Seaside Club is launching its own branded TV series "Crypto Hunters" on a major streaming and TV broadcasting platforms! Token information - Token name: $SEASIDE - Seed Phase: $0,15 - Private sale: $0,3$ - Total Supply: 2,000,000,000 ⏰ Seed Phase planed for December Learn more: - Opportunities: https://77d40765.flowpaper.com/SeasideClubOpportunitiesmatis/ - Tokenomics: https://77d40765.flowpaper.com/SeasideCoinTokenomicsMatis/ - Telegram: https://t.me/+O-ydB2I2CIBjYzhi #SEASIDE#Privatesale#NFTs

ABOUT RAGS TO RICHIE by Alec Monopoly Alec Monopoly is one of the most influential artists of Pop Culture. With a unique universe, he has shown his work on several occasions for Art Basel Miami and has collaborated with worldwide known brands such as Hermès, Jacob&Co, Louis Vuitton or TAG Heuer. Surrounded by NFT experts and Web3 creators, Alec quickly became aware of the importance of what’s been created today in the NFT space. 💰ONLY 2 DAYS LEFT BEFORE MINT! 💰 🗓 DATE REMINDER 🗓 🎩 MINT DATE: July 24th 2022, 2PM EST (6PM UTC) 💰 PRIVATE SALE: Open to Whitelist & Raffle winners at 2PM EST (6PM UTC) 💸 PUBLIC SALE: Open to everyone at 3PM EST (7PM UTC) 👉 More info: https://twitter.com/ragstorichienft/status/1550491484306247682?s=20&t=gzN4NwfON9CLTjI95VhKdQ #NFTs#alec#Privatesale