@legkoenebo · Post #4147 · 24.07.2025 г., 14:35
Мечта или реальность? Лёгкое небо #aviation#evacuation
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
Пребарај: #evacuation
@legkoenebo · Post #4147 · 24.07.2025 г., 14:35
Мечта или реальность? Лёгкое небо #aviation#evacuation
Hashtags
@googlefactss · Post #40339 · 16.12.2025 г., 11:00
Neon tetra fish form orderly queues when escaping through narrow spaces to avoid bumping into each other. Scientists observed groups of these fish passing calmly through small openings without clogging. This behavior helps them evacuate efficiently, unlike humans and sheep who often push and cause jams in emergencies. The study may help improve traffic flow and robot swarm designs. [Source] @googlefactss #FishBehavior🐟#Science#Evacuation#Nature#Research
@intnewsagency · Post #8942 · 26.03.2026 г., 15:43
Evacuation at GES-2 Cultural Center in Moscow An evacuation is underway at the GES-2 Cultural Center in Moscow. Authorities have not yet disclosed the cause of the incident, and official information remains unavailable. Relevant services are actively ensuring the safety of visitors and staff. The situation is ongoing; stay tuned for updates. #Moscow#Evacuation#GES2#Incident The main news of Russia and the world ishere.
Hashtags
@intnewsagency · Post #9239 · 05.04.2026 г., 14:35
Evacuation Underway in Makhachkala Due to Building Collapse Risk Residents of a multi-story building in Makhachkala are being evacuated amid fears the structure may collapse. Recent bad weather caused flooding across towns and villages in Dagestan, worsening regional infrastructure conditions. Local authorities are acting swiftly to ensure public safety. “Ensuring life support and safety is the republic’s priority,” officials stated. #Dagestan#Makhachkala#Evacuation#BadWeather#Safety The main news of Russia and the world ishere.