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

Пребарај: #referandearn

当前筛选 #referandearn清除筛选
MoonPlay

@moonplay_official · Post #34 · 20.06.2024 г., 15:38

Invite Your Friends To Join the Lunar Odyssey🧑‍🚀 Our mission to the moon is just getting started, and we need more brave souls like you! Invite your friends🔊 to join the adventure and help build our lunar colony. The more crew members we have, the stronger our efforts and the greater our discoveries. Every friend you bring on board not only boosts our mission but also unlocks rewards and opportunities for you: 💰one-time bonus; 👛% of space bucks mined by a friend as long as they play (even after the expedition you hire them for); 🤗crew members purchase (different members require different number of friends invited); each hired member will be earning you extra SB/hour. Remember that you need full crew to set off to the moon! Go to Crew tab -> Refer & Earn🔗, share your referral link, and let's make history together! P.S. Just in case you’d run out of friends to invite, there are specially trained bots🤖ready to step in. Nothing can stop you on the way to the moon! Stellar adventures start here:@moon_land_bot🚀 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#ecosystem#blockchain#gamefi#web3#wenlisting#airdropsoon#communityfirst#taptap#clicker#game#invitefriends#referralreward#referandearn

Bounty Hunters 💎

@trustedairdropsss · Post #374 · 10.12.2020 г., 11:56

Want to win big? Invite your friends to join 11Wickets & get rewarded! Download the app👉https://11wickets.sng.link/Dfcpe/ljeu . . . #11Wickets#IndiaOnTheGo#FantasyFootball#FantasySports#Football#ReferAndEarn#Refer#ReferYourFriends

Bounty Hunters 💎

@trustedairdropsss · Post #513 · 14.01.2021 г., 07:53

Want to win big? Invite your friends to join Rummy24 & get rewarded! (T&C apply). Download the app👉https://rummy24.sng.link/Averc/fcz2/lcft . . . #Rummy24#RummyApp#Rummy#RummyGame#IndianRummy#ReferAndEarn#ReferFriends#Invite#Earn#Rewards#Inviteyourfriends#EarnCash#Referafriend#EarnMoney#EarnMoneyOnline#Games#CardGames#DownloadTheApp