@sgmrt · Post #2473 · 01.09.2025 г., 01:19
[CCL] UPDATE: Train services between #Promenade and #MarinaBay have resumed their scheduled operations. Free regular bus services have ceased. - SMRT
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
Пребарај: #marinabay
@sgmrt · Post #2473 · 01.09.2025 г., 01:19
[CCL] UPDATE: Train services between #Promenade and #MarinaBay have resumed their scheduled operations. Free regular bus services have ceased. - SMRT
Hashtags
@sgmrt · Post #2472 · 01.09.2025 г., 01:14
[CCL] UPDATE: Train services are progressively resuming their scheduled service between #Promenade and #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #2471 · 01.09.2025 г., 01:04
[CCL] UPDATE: Due to a train fault, train service is expected to recover its scheduled service in 15 minutes between #Promenade and #MarinaBay. We apologise for any inconvenience caused. Please approach our station staff if you need further assistance. - SMRT
Hashtags
@sgmrt · Post #2470 · 01.09.2025 г., 00:54
[CCL] Update: Free regular bus services are available between #Promenade and #MarinaBay. You may download an e-Travel Chit as proof of your travel at https://bit.ly/39HsrAl if your journey has been affected. - SMRT
Hashtags
@sgmrt · Post #2468 · 01.09.2025 г., 00:49
[CCL]: Due to a train fault, there is no train service between #MarinaBay and #Promenade. Free regular bus services are available between #MarinaBay and #Promenade. https://bit.ly/3JHKRD2 - SMRT
Hashtags
@sgmrt · Post #1468 · 20.06.2022 г., 05:58
[CCL] UPDATE: Additional 10mins train travel time from #Promenade to #MarinaBay. We are working to recover service. - SMRT
Hashtags
@URASingapore · Post #910 · 24.07.2024 г., 10:00
Singapore’s hot weather can be a bother if you take a stroll at Marina Bay. But with our solar-powered breeze shelters strategically placed along the promenade, you don’t need no Oppas to shelter you from the heat! 🌬 #UrbanDesign#DiscoverSingapore#MarinaBay
@sgmrt · Post #1894 · 22.03.2024 г., 02:35
[CCL] UPDATE: Normal train service has resumed. Free regular bus service between #PayaLebar and #DhobyGhaut / #MarinaBay has ceased. - SMRT
Hashtags
@sgmrt · Post #1893 · 22.03.2024 г., 02:19
[CCL] UPDATE: Additional 20 mins train travel time from #PayaLebar to #DhobyGhaut / #MarinaBay, due to a train fault. Free regular bus service is available between #PayaLebar and #DhobyGhaut / #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #1892 · 22.03.2024 г., 01:55
[CCL] UPDATE: Additional 30 mins train travel time from #PayaLebar to #DhobyGhaut / #MarinaBay, due to a train fault. Free regular bus service are available between #PayaLebar and #DhobyGhaut / #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #1884 · 08.02.2024 г., 03:14
[CCL] UPDATE: Due to a signal fault, please add additional 20 minutes travel time between #DhobyGhaut, #MarinaBay and #PayaLebar. Free regular bus services are available between #DhobyGhaut, #MarinaBay and #PayaLebar. - SMRT
Hashtags
@sgmrt · Post #1883 · 08.02.2024 г., 02:19
[CCL] UPDATE: Due to a signal fault, please add additional 15 minutes travel time between #DhobyGhaut, #MarinaBay and #PayaLebar. Free regular bus services are available between #DhobyGhaut, #MarinaBay and #PayaLebar. - SMRT
Hashtags