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

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #146 · 16 сеп.

Функция 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

Hashtags

Резултати

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

Пребарај: #civilization

当前筛选 #civilization清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #587 · 19.08.2025 г., 03:22

🌎 The Caral civilization in Peru built the oldest known city in the Americas around 2600 BCE. Its pyramid complexes predate the Inca by millennia and show early urban planning, trade, and communal gatherings long before written history in the region. ✨ #history⚡#archaeology⚡#civilization 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #874 · 07.10.2025 г., 20:11

🌎 The mysterious Harappan city of Dholavira, in India’s Gujarat region, features an intricate water management system with reservoirs, underground drains, and stone-lined wells. Archaeologists date the city from 3000 BCE to 1500 BCE and note its unique use of stepwells and multi-level reservoirs for collecting and distributing scarce water in the desert. ✨ #archaeology⚡#civilization⚡#mystery 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #410 · 24.10.2025 г., 12:31

🌍 The boundaries of ancient Mesopotamia shifted as rivers changed course, causing cities to move or vanish. River geography shaped the rise and fall of some of history’s earliest civilizations. ✨ #historicalgeography⚡#rivers⚡#civilization⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1121 · 11.12.2025 г., 22:11

🌎 Massive underground chambers beneath the ancient city of Derinkuyu in Turkey could shelter up to 20,000 people. This multi-level complex includes ventilation shafts, stables, kitchens, wells, and a school. Archaeologists believe it was carved from soft volcanic rock over 2,000 years ago to protect residents from invasions. ✨ #archaeology⚡#civilization⚡#Turkey 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #678 · 31.03.2026 г., 20:31

🌍 The lost city of Cahokia once stood near present-day St. Louis, with earthen mounds and a population rivaling European cities around 1100 CE—making it North America’s largest urban center before Columbus. ✨ #historicalgeography⚡#archaeology⚡#civilization⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Environment & Climate Change

@Enviro_Climate · Post #372 · 18.09.2021 г., 13:21

Sea Secrets - Arash Sharifi Arash Sharifi, a Ph.D. candidate of marine geology and geophysics at the UM Rosenstiel School, takes us into the compelling world of #paleoclimate research. By using climate, #historical, and #archeological records, Sharifi shows how climate change has been affecting the world since the beginning of human #civilization. @Enviro_Climate https://youtu.be/ovy-57jx85Q?t=3

Yukiokhruner

@yukiokhruner · Post #52 · 01.08.2022 г., 10:04

L'esigenza spontanea di uno spazio sacro sembra essere venuta meno nell'ultima forma della nostra civiltà #vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#civiltà#civilization#egemonia#hegemony#sacro#sacred#suora#nun