@talks · Post #250 · 13.03.2018 г., 17:33
#Nietzsche
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
Пребарај: #nietzsche
@talks · Post #250 · 13.03.2018 г., 17:33
#Nietzsche
Hashtags
@talks · Post #244 · 19.02.2018 г., 05:52
#GREATGOAL=STRENGTH #NIETZSCHE
Hashtags
@Aetatesolis · Post #4360 · 19.04.2025 г., 17:21
"He who can not obey himself will be commanded." -Nietzsche The line cuts deep because it's true. We've all felt it. The moment we betray what we know we should do. The quiet voice we ignore until someone louder takes control. Do shout to yourself. #discipline #nietzsche AETATESOLIS
Hashtags
@Aetatesolis · Post #3962 · 28.02.2025 г., 22:15
🏛Nietzsche's The Last Man "The earth hath then become small, and on it there hoppeth the last man who maketh everything small. His species is ineradicable like that of the ground-flea; the last man liveth longest." - Nietzsche Nietzsche wrote about what he called "The Last Man". The Last Man wants everyone to be the same, to have the same, and to say the same thing. The Last Man wants to feel confident that everything is known and understood and is being handled correctly. The Last Man finds reassurance in collective consensus, which he values more highly than truth or excellence. The Last Man is a flat line - incapable of awe or passion or the creation of values. #nietzsche #zarathustra *Picture: Starttheworld AETATESOLIS
Hashtags
@filosofarsogood · Post #12497 · 26.04.2025 г., 10:58
Se il 29 aprile "Dio era morto", a fine maggio sarà sicuramente "Rick DuFer è morto" 😂 Con l'uscita del nuovo libro per Feltrinelli abbiamo un po' esagerato con l'organizzazione delle presentazioni, ma ho così tante cose da raccontarvi che non ho potuto resistere. Ci vediamo un po' dappertutto, presto arriveranno date anche al sud, ma nel frattempo Roma, Torino, Milano, Cesena e tante altre città saranno raggiunte! Spero di vedervi numerosi, questo libro non vi lascerà indifferenti. Tutte le info qui: https://www.dailycogito.com/eventi #rickdufer#dioeramorto#filosofia#feltrinelli#instabook#eventi#dalvivo#dailycogito#renatominutolo#nietzsche