@social_justice_watch · Post #17881 · 09.02.2023 г., 17:47
Sorry for what, exactly? 👀#Autism#autistic#ActuallyAutistic#AutismAcceptance#AutismAcceptancesource
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
Пребарај: #autistic
@social_justice_watch · Post #17881 · 09.02.2023 г., 17:47
Sorry for what, exactly? 👀#Autism#autistic#ActuallyAutistic#AutismAcceptance#AutismAcceptancesource
@social_justice_watch · Post #17904 · 09.02.2023 г., 18:42
Betcha it would improve accessibility AND accuracy. Just sayin'. #Autism#autistic#ActuallyAutistic#autistictwittersource
@social_justice_watch · Post #18048 · 28.04.2023 г., 14:30
Gets me going every time. #Autism#autistic#ActuallyAutistic#pathologicaldemandavoidancesource
@social_justice_watch · Post #18054 · 02.05.2023 г., 19:17
It’s only a real choice if it’s a fully informed one. Identity First Language = Autistic person, am/is Autistic Person First Language = person with Autism, have/has Autism #autism#autistic#ActuallyAutistic#Autisticmemessource
@social_justice_watch · Post #17919 · 14.02.2023 г., 16:55
Maybe you’re not doing it wrong, you just haven’t found someone who gets you yet. ❤️ #Autism#autistic#ActuallyAutistic#autistichumorsource
@social_justice_watch · Post #17905 · 09.02.2023 г., 18:44
And this is one of the many reasons why self-identification is a thing. (Applicable to ADHDers as well.) #Autism#autistic#ActuallyAutistic#ADHD#AuDHDsource
@social_justice_watch · Post #18016 · 05.04.2023 г., 18:45
You can’t win, so why give them any of your f@cks? 😉 #autism#Autistic#ActuallyAutistic#AutismAcceptance#AutismAwarenesssource
@social_justice_watch · Post #18035 · 18.04.2023 г., 22:21
Actual footage. #pathologicaldemandavoidance#pervasivedriveforautonomy#autistic#ActuallyAutisticsource
@social_justice_watch · Post #18119 · 29.06.2023 г., 04:39
For some reason, even people who understand the importance of representation for other groups can struggle to apply the same logic to Autistic (and otherwise disabled) people. <cough cough #ableism> #autistic#ActuallyAutistic#nothingaboutuswithoutussource
@social_justice_watch · Post #18060 · 09.05.2023 г., 21:39
If your first instinct is to dismiss this on the grounds of “but that would be really messed up,” you’re about halfway to the point. Keep going. #Autism#autistic#ActuallyAutistic#AutismAcceptance#appliedbehavioranalysissource
@social_justice_watch · Post #17909 · 09.02.2023 г., 19:02
CW: ABA, signs of trauma. I don’t normally do content warnings, but ngl: this one just hurts. Take care of yourself and scroll on by if you’re not in the right space for it. (And I promise I’ll make it up to you next week.) #Autism#Autistic#ActuallyAutistic#ABA#banABAsource
@social_justice_watch · Post #17968 · 07.03.2023 г., 22:50
Ableist stereotypes are bullshit. Also, we know our neurokin when we see them. 👀😉 #Autism#autistic#ActuallyAutistic#AuDHD#Neurodivergent#AutismAcceptancesource