@wallpapersarena · Post #6674 · 14.12.2024 г., 06:30
#Superheroes @WallpapersArena
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
Пребарај: #superheroes
@wallpapersarena · Post #6674 · 14.12.2024 г., 06:30
#Superheroes @WallpapersArena
Hashtags
@wallparpes_hd · Post #842 · 25.04.2020 г., 13:14
Red Hood 2020 #superheroes 📱 Los mejores Wallpapers ⭐📱 @wallparpes_hd
Hashtags
@wallparpes_hd · Post #759 · 21.04.2020 г., 17:54
Hellboy Fanart #superheroes 📱 Los mejores Wallpapers ⭐📱 @wallparpes_hd
Hashtags
@wallparpes_hd · Post #662 · 12.04.2020 г., 17:15
Venom X Punisher #superheroes 📱 Los mejores Wallpapers ⭐📱 @wallparpes_hd
Hashtags
@wallparpes_hd · Post #120 · 19.03.2020 г., 17:20
Doctor Strange In The Multiverse Of Madness #superheroes 📱 Wallpapers Full HD 📱⭐ https://t.me/joinchat/AAAAAE65rdIFyMNq1qiq7A
Hashtags
@wallparpes_hd · Post #108 · 18.03.2020 г., 22:31
Deadpool Cool #superheroes 📱 Wallpapers Full HD ⭐📱 https://t.me/joinchat/AAAAAE65rdIFyMNq1qiq7A
Hashtags
@wallparpes_hd · Post #93 · 18.03.2020 г., 22:27
Doctor Strange In The Multiverse Of Madness #superheroes
Hashtags
@wallparpes_hd · Post #89 · 17.03.2020 г., 23:13
The Punisher Man #superheroes
Hashtags
@wallparpes_hd · Post #88 · 17.03.2020 г., 23:12
Deathstroke #superheroes
Hashtags
@wallparpes_hd · Post #75 · 17.03.2020 г., 14:35
Justice League New 2020 #superheroes
Hashtags
@images · Post #1543 · 30.05.2024 г., 13:43
🍿 The Last Adventure of 'The Umbrella Academy'! 📆Premiere: August 8, 2024 🎭Genre: #Superheroes · #Drama The Hargreeves return for one final mission in the fourth and last season of 'The Umbrella Academy'. This time, without their powers, they must adapt to normal life, though chaos still ensues. 🌀 Elliot Page, Tom Hopper, and the rest of the original cast are back, along with new additions Nick Offerman and Megan Mullally. The curious part: the Thibedeaus, college professors with extreme déjà vu! 🤯 Reginald Hargreeves is back, leading a dark empire, while a mysterious organization believes reality is a lie. Don’t miss the trailer set to 'The Final Countdown'. 🎬💥 > 𝘴𝘦𝘳𝘪𝘦𝘴 · 🚀𝘣𝘰𝘰𝘴𝘵
Hashtags
@images · Post #1746 · 20.12.2024 г., 08:54
🍿 Superman: Legacy, the Rebirth of Hope ☀️ 📆Release: July 11, 2025 🎭Genre: #Action · #Fantasy · #Superheroes I just watched the trailer, and I’m filled with excitement. James Gunn’s Superman (Guardians of the Galaxy) focuses on kindness. David Corenswet (Hollywood) dons a colorful suit, flying and shielding a little girl. Rachel Brosnahan (The Marvelous Mrs. Maisel) brings a spark to Lois Lane, while Nicholas Hoult (Mad Max: Fury Road) promises a compelling Lex Luthor. Guy Gardner, with his bowl cut, couldn’t be more perfect. And Krypto, that dog, melts my heart. This movie looks like it’ll radiate optimism, reminding us that the world needs heroes who inspire. I can’t wait to see it. 🎉
Hashtags