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

Пребарај: #rank

当前筛选 #rank清除筛选
MoonPlay

@moonplay_official · Post #71 · 20.07.2024 г., 07:54

Welcome, New Space Cadets! 💫 Since Monday, we've welcomed an incredible 600k new space cadetsto our mission! 🚀 With so many explorers joining, here's a quick reminder about the journey ahead. Your ship and crew are built for one epic trip only. After each successful mission to the moon, you level up and need to construct a brand new spaceship🚀 and recruit a fresh crew to set off on your next journey. 🌌New Ship: Each mission gives you the opportunity to build even cooler, more powerful ships. Your level increases with every successful expedition, unlocking better designs and greater mining power. 🌌Fresh Crew: Invite new friends to join your adventures. Each new expedition requires a full crew, and more friends mean greater strength and success. No friends? No prob! Use special bots. 🌌Continuous Exploration: The adventure never ends! Keep exploring the cosmos, completing missions, and reaping stellar rewards. 🌌Balance Intact: Levelling up doesn’t reset your Space Bucks balance. You keep all your hard-earned Space Bucks as you progress. ℹ️ For more info, check the mission manual here. Every journey helps you level up, bringing you closer to mastering the cosmos. So gear up, build your fleet, and keep pushing the boundaries of space exploration: the end of season 1 & the first token airdrop are coming!🔔 👉Start your To The Moon adventure now!👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#ecosystem#blockchain#gamefi#web3#wenlisting#squad#rank#communityfirst#taptap#clicker#game

MoonPlay

@moonplay_official · Post #69 · 18.07.2024 г., 15:10

Squad Multiplier: Earn More💰 If you haven’t joined a squad yet, you’re missing out on a fantastic way to turbocharge your 💸 earnings and complete expeditions faster. Whether you team up with friends or join forces with other players, being in a squad is your ticket to higher earnings. Head to the Crew tab—> Squads👥, check out the top squads on the leaderboard, or create your own and invite others to join. The higher your squad’s rank, the bigger the Space Bucks multiplier, up to a whopping 1.5x! After three days in a squad ⏰, you start benefiting from the squad’s multiplier. Your squad’s rank boosts your: 💸 Mining income ✅ Mission rewards 🌕 Expedition rewards 💫 Star Dust rewards So, what are you waiting for? Team up, level up, and watch your earnings skyrocket. Who’s going to be the first Rank 3 Squad in the game? Let’s wait and see! 👉Start your To The Moon adventure now!👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#ecosystem#blockchain#gamefi#web3#wenlisting#squad#rank#communityfirst#taptap#clicker#game

MoonPlay

@moonplay_official · Post #70 · 19.07.2024 г., 12:48

Can You Catch The LEPrechaun? 🍀 Hey Space Cadets! We're excited to announce a fantastic new partnership with LEPrechaun🎩! This summer, LEPrechaun is bringing a bottomless pot of $LEP coins - and you've got a chance to join the gold rush. Join their pre-launch on Telegram now and secure an airdrop for early users! But that's not all! LEPrechaun is also introducing 4 fresh missions✅ for you, our brave explorers. Head to the Missions tab and check them out to boost your progress in ToTheMoon! and start earning $CLOVER in LEPrechaun bot. Don't miss out on this stellar opportunity! 👉Start your To The Moon adventure now!👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#LEPrechaun#partnership#ecosystem#blockchain#gamefi#web3#wenlisting#squad#rank#communityfirst#taptap#clicker#game