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

Пребарај: #earntokens

当前筛选 #earntokens清除筛选
ChatGPT AI Technology News

@chatgpt_officialnews · Post #119 · 26.05.2025 г., 16:02

📰 AI News Update: 🤖 In the world of artificial intelligence, researchers have made significant strides in natural language processing. A new model developed by a team at a leading university has surpassed previous benchmarks in understanding context and nuances in text. This advancement could revolutionize chatbots, translation services, and content analysis tools. Moreover, a breakthrough in AI ethics has been achieved with the development of a framework that prioritizes fairness and transparency in machine learning algorithms. This approach aims to mitigate biases and discrimination, ensuring AI systems make ethical decisions in various applications. On the business front, tech giants are investing heavily in AI-driven solutions to enhance customer experiences and streamline operations. Companies across industries are increasingly leveraging AI to drive innovation... ➖➖➖➖🔻 🤖 BOT: @Chatgpt_OfficialBOT 💎@Chatgpt_OfficialNews #️⃣#NeuralHubAI#ReferralContest#EarnTokens#WeeklyAirdrop ➖➖➖➖🔺

ChatGPT AI Technology News

@chatgpt_officialnews · Post #117 · 24.05.2025 г., 11:01

🚀 Referral Contest Heating Up – $200 Weekly Prize! The race is ON, and here are your current top referrers: 🥇Amir – 30 referrals 🥈Pixel Wiz* – 29 referrals 🥉Ref Champ* – 23 referrals But it’s not over yet — you still have time to climb the leaderboard and win your share of the $200 prize this week! ⚡️Just invite your friends using your referral link 😵Every referral brings you closer to the top 🏆Top 3 win: $100 • $60 • $40 Let’s go! Start inviting now and grab that top spot! 📈 ➖➖➖➖🔻 🤖 BOT: @Chatgpt_OfficialBOT 💎@Chatgpt_OfficialNews #️⃣#NeuralHubAI#ReferralContest#EarnTokens#WeeklyAirdrop ➖➖➖➖🔺

Airdrop Strikers™

@airdropstrikers · Post #1187 · 16.04.2023 г., 15:33

By participating in our airdrop campaign, you will not only get a chance to earn JIM tokens, but you will also get an opportunity to be a part of the most revolutionary project of the year. So, don't miss out on this amazing opportunity and join us now! 🙌 https://gleam.io/CmtmH/jimmy-project-airdrop-campaign Spread the word and invite your friends to join the Jimmy project community. Together, we will soar to new heights!🚀#JimmyProject#Airdrop#Cryptocurrency#Blockchain#EarnTokens#JoinUsNow Total $25.000 worth JIM Token supply will be distributed to participants according to points collected. Complete all tasks to benefit airdrop in full! 10 Referral Champions will share 1000 USDT Prize pool!