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

Пребарај: #farmix

当前筛选 #farmix清除筛选

☺️Farmix – Latest News Review and Upcoming AMA Updates and changes: ➡️Increased RP for Lending in Farmix – in3⃣ The RP farm for providing liquidity in TON, USDT, NOT, stTON and tsTON, which can later be exchanged for protocol tokens, has been increased several times. ➡️ When closing a position, you can choose to convert LP into a credit token. At the moment, the function works in the $TON/$USDT pair and only for new positions. The update has fully prepared the team for the emergence of new highly liquid stablecoins with increased leverage up to 8x. ➡️Roadmap released ➡️ The formula for calculating the Estimate Profit indicator has been updated. ➡️ The #Farmix RP leaderboard in TMA has appeared. 🎙 The team announced an upcoming AMA session, where they will discuss the current results and plans of the project. The broadcast will take place on April 7 on the #Farmix Telegram channel at 19:00 UTC+3. You can ask questions through the form, and 3 participants with the most interesting questions will receive $USDT each. 📖 If you have any questions about the project, you can ask them in the chat. There is also a step-by-step text guide for opening a farm. Farmix | Channel | Documentation

Hashtags

🙏TON Society just added SBT Points For now not all SBTs have amount of points that their owners will receive, but a trend is already visible — the more valuable in terms of the number of points are #DeFi SBTs and for contributors to the blockchain. If you want to earn more points you have you should definitely get these SBTs: 💎 8 more days to get🙏9,500 for two valuable SBT Farmix in the BroBot contest✋ 💎12 days to get tBook SBT Late Night DeFi with general speed 🙏27,000 points. #TON#BroBot#SBT#Farmix

😎–Hey Bro! $1,500 and free SBTs for you! We’re launching a new quest with Farmix — leveraged lending liquidity protocol. Prize pool: just gain 600 XP and hold Lending for a chance to win one of 150 $10 prizes, extra XP, and guaranteed #SBT from TON Society! 🚀Join the quest now and share with your Bros! 📖 Deadline: Dec. 27, 15.00 UTC #TON#BroBot#contest#Farmix

🧑‍💻Review: Farmix – The Innovative Force in TON DeFi ☺️Farmix appeared relatively recently, it is a semi-finalist of #DoraHacks hackathon. In a nutshell, it is a marginal farming protocol that allows you to significantly increase the profitability of your farms by using leverage. 🪙 We have already tested their farming pools a couple of weeks ago, everything went well and without complications. At that time, the APR in the farms was very high, some pairs gave up to 9,000% APR. Below is a short guide for working with Farmix. 🐷 On average, #Farmix farms are 3-5 times higher than in #DEX pools. There are two options to earn income for providing your assets: Lending and Farms. We will look at the Farms option, because this is the most interesting: 🟡Log in to Farmix and connect your MTW wallet. 🟡 Go to the "Farmers" tab and find the pair you are interested in, for example we will use the STORM/TON pair. 🟡 First, select "Borrow asset" — this is the asset in which you will take a loan for leverage in the farm. In the case of the STORM/TON farm, only the TON loan asset is available. 🟡Enter in the $STORM/$TON fields how much STORM and TON you will provide as collateral. In #Farmix you can open a farm with one token, it is not necessary to provide both tokens, as the smart contract itself will convert the tokens into a 50/50 pair and form LP tokens. 🟡Select the leverage (Leverage slider) with which you want to open the farm. The higher the leverage, the higher the APR of the farm, but the liquidation risks also increase. 🟡Click Open position at the bottom, sign the transaction in the wallet and in a few minutes your first farm will be open. ⚠️Important: Please note that leverage is only provided for collateral in $TON , $USDT , $tsTON, $stTON, $NOT . Any position with leverage > 1 has its own health factor. HF > 1.3 is considered moderate, HF = 1 - the position is liquidated. 📊 At first glance, the guide may seem complicated, but everything is generally intuitive. If you have any questions about the work of the project, farms, etc., you can ask them 🔔in our chat. You will also receive RP points for staking and farming, more details in the "Reward activities" tab. And as usual #NFR#DYOR Farmix | Channel | Project documentation