TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

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

Резултати

Пронајдени 1 слични објави

Пребарај: #transgenders

当前筛选 #transgenders清除筛选
Trump's Ear

@trumpsear_tg · Post #1520 · 17.09.2025 г., 16:01

In the wake of the Minneapolis Catholic church shooting, senior Justice Department officials are weighing proposals to limit transgender people’s right to possess firearms, according to two officials familiar with the internal discussions. The talks, described as preliminary in nature, appear to build on an idea that has gained some currency in conservative media since the Minneapolis shooting that killed two children and injured 21, most of them children, at Annunciation Catholic Church, an attack that police say was carried out by a 23-year-old transgender woman. Such a move would represent a dramatic escalation of the Trump administration’s fight against the rights of transgender Americans. President Donald Trump has issued a series of executive orders on the topic, including one barring transgender people from serving in the military and another ordering federal prisons to move transgender inmates to facilities corresponding to their gender assigned at birth. In addition, the idea of restricting gun rights has long been a red line for conservatives, with many Republican lawmakers and gun rights groups opposing red flag laws and or other policies aimed at keeping guns away from people suffering from mental health issues. But Justice Department leadership is seriously considering whether it can use its rulemaking authority to follow on to Trump’s determination to bar military service by transgender people and declare that people who are transgender are mentally ill and can lose their Second Amendment rights to possess firearms, according to one Justice official. Another senior Justice Department official cautioned that any such proposal, should it gain steam, would likely run into legal complications. Millions of Americans have mental health issues and many take medications, but are not a danger to society and therefore cannot have their rights infringed upon. #DOJ#transgenders#firearms 👂More on Trump's Ear ⚠️