@wukongcm · Post #46 · 19.11.2024 г., 03:27
Hey WUKERS, 🔥 This Game Is Yours, We Need You! 👉 Show yourself: https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
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
Пребарај: #wukong
@wukongcm · Post #46 · 19.11.2024 г., 03:27
Hey WUKERS, 🔥 This Game Is Yours, We Need You! 👉 Show yourself: https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
@wukongcm · Post #44 · 14.11.2024 г., 05:16
🔥Welcome to Wukong – where every step is a challenge. Here, you don’t just earn Wk; you face fierce trials to move closer to the true treasure – the boundless power of the sacred scrolls. Let's join Wukong to conquer the missions and discover the secret rewards that await you. ➡️ Are you ready to step into legend? https://t.me/bmwukongbot/join?startapp=L29WAAMR #Wukong
Hashtags
@wukongcm · Post #42 · 25.10.2024 г., 07:39
⚡️ Transform your crypto experience with CoinEx, just like Wukong's 72 transformations. Get started today! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #39 · 21.10.2024 г., 07:47
⚡️ Defy the odds like Wukong in battle. On CoinEx, every trade is a step toward your next big victory! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #36 · 17.10.2024 г., 07:51
✔️ Master the art of trading, just like Wukong mastered his powers. Start with CoinEx today and become a crypto legend ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #34 · 12.10.2024 г., 07:55
✔️ Forge your own crypto legend with CoinEx, just like Wukong in his journey. Start trading today! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #33 · 11.10.2024 г., 07:53
💥 Every trade is a step closer to victory! CoinEx is your battlefield—are you ready to conquer? ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #31 · 09.10.2024 г., 08:26
👍Like Wukong battling epic bosses, conquer your crypto journey with CoinEx. Sign up now and get ready to take on the world of digital assets! ➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh #Wukong#CoinEx
@wukongcm · Post #43 · 26.10.2024 г., 07:42
💥 Take on the crypto world like a true warrior with OKX. Your journey starts now! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #40 · 22.10.2024 г., 07:58
✔️ Strike fast and win big, just like Wukong! Join OKX and experience lightning-fast trades! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #37 · 18.10.2024 г., 07:53
✨ Journey through the crypto universe with OKX. Your path to victory is clear—start trading now! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX
@wukongcm · Post #35 · 16.10.2024 г., 07:48
🎁 No need for 72 transformations—on OKX, all you need is one account to start trading! ➡️ Get reward on OKX: https://www.okx.com/join/84940417 #Wukong#OKX