@MostInspiring · Post #1966 · 04.04.2024 г., 02:10
Must watch. #MustWatch What matters the most is.. Not who's mistake but whose life
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
Пребарај: #mustwatch
@MostInspiring · Post #1966 · 04.04.2024 г., 02:10
Must watch. #MustWatch What matters the most is.. Not who's mistake but whose life
Hashtags
@MostInspiring · Post #1515 · 16.10.2020 г., 09:01
#MustWatch @MostInspiring Video Click to Join 👇👇👇👇 You will certainly Experience the good Feeling after seeing this Video
Hashtags
@rusembcy · Post #1341 · 21.11.2023 г., 06:17
#MustWatch To fully understand the genesis of the current situation in Ukraine, how the rise of Neo-Nazism came to be and how the far-right Russophobic ideology and groups gained power over a brotherly nation one must take a retrospect view. 📣 World renowned filmmaker and actor, Academy award winner Nikita Mikhalkov tells and explains just that, with proven facts and archival footage to show the truth, in an emergency hour-long episode of his author's programme BesogonTV. The Western mainstream media will never report on these facts, sweeping under the rug anything that damages the current anti-Russian narrative, hoping the audiences have no recollection of the sequence of the events. Watch to jog your memory. Warning: the video contains sensitive images, viewer discretion advised.
Hashtags
@MostInspiring · Post #760 · 04.05.2019 г., 02:51
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️ One of the best videos ever! Absolutely brilliant in conveying the most needed message of today with no words! We wish this video goes viral across India and the world to create an awareness where education is sold. @MostInspiring #MustWatch
Hashtags
@MostInspiring · Post #655 · 31.03.2019 г., 04:49
Will Power #mustwatch @MostInspiring
Hashtags
@MostInspiring · Post #490 · 13.02.2019 г., 15:01
#MustWatch@mybestcollection
Hashtags
@MostInspiring · Post #329 · 23.12.2018 г., 22:37
@MostInspiring #mustwatch
Hashtags
@MostInspiring · Post #313 · 19.12.2018 г., 23:18
#MustWatch @MostInspiring
Hashtags
@positivenewss · Post #232 · 23.06.2020 г., 09:17
What is real kindness #mustwatch @Highimpact
Hashtags
@primevisa_uz · Post #205 · 21.07.2022 г., 04:43
Bizga ham nasib qilsin 🙌 #mustwatch
Hashtags
@positivenewss · Post #143 · 12.04.2020 г., 05:07
Amazing Video 🔗👆 #MustWatch
Hashtags
@MostInspiring · Post #133 · 24.10.2018 г., 00:06
@MostInspiring #MustWatch
Hashtags