Функция sub в regex может принимать функцию в качестве аргумента repl.
📄 Из документации:
If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string.
То есть для каждого совпадения будет вызвана функция для вычисления замены вместо замены на одну и ту же строку для всех совпадений.
Иными словами, для замены разных совпадений на разные строки не потребуется запускать re.sub() много раз для каждой строки замены. Достаточно определить функцию, которая вернёт строку для каждого из совпадений.
Описание слишком запутанное🤔, давайте лучше рассмотрим на простом примере:
Создаем карту замены. То есть какие строки на какие требуется менять.
remap = {
'раз': '1',
'два': '2',
'три': '3',
'четыре': '4',
'пять': '5',
}
Пишем функцию поиска строки для замены. Единственным аргументом будет объект re.Match.
Используя данные этого объекта мы вычисляем замену on-the-fly!
def get_str(match: re.Match):
word = match.group(1)
return remap.get(word.lower()) or word
Пример текста.
text = '''Раз Два Три Четыре Пять
Вместе будем мы считать
Пять Четыре Три Два Раз
Мы считать научим вас
'''
Теперь запускаем re.sub и вместо строки замены (repl) подаём имя функции.
(Данный паттерн ищет отдельные слова в тексте)
>>> print(re.sub(r'(\w+)', get_str, text))
1 2 3 4 5
Вместе будем мы считать
5 4 3 2 1
Мы считать научим вас
Думаю, достаточно наглядно 🤓
#libs#regex
Ørsted Gardens.
Ørsted Gardens transformed a dilapidated building (see third image) into a new social space with semi-private decks for the individual residents.
Ørsted Gardens by Tegnestuen Lokal – "If we want to achieve a sustainable future, we cannot rely on only building sustainable buildings going forward. We need to have a visionary method of transforming and adapting existing buildings to meet our changing needs. Ørsted Gardens is an example of a project that brings a generic renovation to a new level, improving the visual and social environment for residents and visitors alike."
#arch_shovel#architecture#archdaily#facadedesign
3XN Architect’s proposal for SRPJ in Tokyo.
The design for The Shibuya Upper West project, 𝗧𝗵𝗲 𝗪𝗮𝘃𝗲𝘀, began from the inside out – understanding the target user groups, identifying key project aspirations for this new ecosystem nestled within Shibuya and Tokyo, and ensuring a clear, uncomplicated method of articulation that amplifies the spatial qualities within, without compromising the functionality and efficiency of a retail development.
Taking cues from nature as a means of creating balance between the more hard edge, urban environment of Shibuya, the simple massing articulation, or gesture mimics the pattern of waves and their undulating movement, with imagery that also evokes the contemplative and soothing gestures of raked brush strokes seen in tranquil rock gardens, evoking a sense of calm and excitement, easily recognisable and yet able to stand apart from the surrounding context.
Huge congratulations to Snohetta for their winning design!
#3xnarchitects#tokyo#facadedesign #facade#arch_shovel
‘Where’s House Warehouse’ by pbm Architects defies typical warehouse stereotypes with an ethereal design in Bangkok. The architects crafted a multi-use space blending office and storage functions. Its facade, made of glass cuboids, breaks the monotony of industrial contexts. The concept evolved from merging living, working, and storage areas seamlessly, fostering interaction and fluidity.
Architecture: PBM Architects
Images: Spaceshift Studio
📍Bangkok, Thailand
.
#facadedesign#glassarchitecture#thaiarchitecture#industrialarchitecture#arch_shovel
Facades for the OPPO Super Flagship Store.
Bamboo inspired the facade design for the OPPO Super Flagship Store in the city of Guangzhou.
An important source of food, clothing, housing, and transportation for people in Guangzhou in ancient times, the design adds a contemporary twist to the vernacular architecture of the city.
Photos: CreatAR images
Architecture: UnStudio
#unstudio#benvanberkel#materialmonth#architecture#facadedesign#arch_shovel
Do you know how many silver spheres are on the facade of the Hanjie Wanda Square in Wuhan, China?
42,333.
While they all may look identical, their specific positions involving each other recreate the effect of movement and reflection in water or the sensuous folds of silk fabric.
Photos: Edmon Leong / UNStudio
#unstudio#facades#facadedesign#architecture#retaildesign#lightingdesign#arch_shovel
From cotton to culture - Oscar Niemeyer Sphere - Baumwollspinnerei.
#leipzig#visitleipzig#architecturephotography#minimalism#facadedesign#archidaily#arch_shovel
Can you guess what inspired Unstudio architecture’s design for the facade elements of the Shenzhen Maritime Museum?
Comment your answer below!
#unstudio#ceramicdesign#facadedesign#worldmuseums#museumsoftheworld#museumdesign#architecture#architecturaldesign#arch_shovel