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

Резултати

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

Пребарај: #camouflage

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

@interesting_planet_facts · Post #1364 · 04.04.2026 г., 12:11

🌎 Some octopus species, like the mimic octopus, can rapidly change their color and skin texture to blend into diverse backgrounds or imitate venomous sea creatures. This camouflage is controlled by specialized skin cells called chromatophores, iridophores, and leucophores, allowing them to avoid predators or catch prey. ✨ #animals⚡#camouflage⚡#ocean 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1320 · 27.02.2026 г., 22:11

🌎 Parrotfish dazzle reefs with scales in neon blues, pinks, and greens, while the stonefish hides perfectly among rocks thanks to its bumpy, mottled skin. Stonefish toxins can cause serious injury if stepped on. ✨ #animals⚡#camouflage⚡#ocean 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1220 · 13.01.2026 г., 22:11

🌎 The peacock mantis shrimp stands out for its dazzling rainbow armor and lightning-fast punch. Its eyes detect polarized and multispectral light far beyond human vision. This shrimp's punch can shatter aquarium glass and accelerate as fast as a bullet—up to 23 meters per second. ✨ #animals⚡#camouflage⚡#ocean 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1032 · 14.11.2025 г., 18:11

🌎 Few animals rival the peacock mantis shrimp for color and camouflage. Its shell displays vivid blues, reds, and greens, helping it blend with coral while startling predators. The mantis shrimp’s eyes detect polarized light and twelve color channels—far more than humans, who see only three. ✨ #animals⚡#camouflage⚡#ocean 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1188 · 03.01.2026 г., 18:11

🌎 Arctic hares survive the icy tundra by changing their fur color—white in winter to blend with snow, brown or gray in summer for camouflage. Adults can leap up to 2 meters in a single bound to escape predators. ✨ #animals⚡#adaptation⚡#camouflage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #957 · 23.10.2025 г., 22:11

🌎 Harlequin toads flaunt striking black, yellow, and orange patterns to warn predators of their skin toxins, while the common leaf insect mimics green leaves so closely that even its legs resemble plant veins. Scientists have documented over 3,000 species of leaf-mimicking insects worldwide. ✨ #animals⚡#adaptation⚡#camouflage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #845 · 01.10.2025 г., 22:11

🌎 The leafy sea dragon, native to southern Australia, blends perfectly with seaweed thanks to leaf-like extensions on its body. These fins don’t propel it but provide camouflage from predators. Leafy sea dragons reach up to 35 centimeters in length and are closely related to seahorses. ✨ #adaptation⚡#camouflage⚡#ocean 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1159 · 24.12.2025 г., 12:11

🌎 The orchid mantis of Southeast Asia blends in with flowers thanks to petal-shaped limbs and white, pink, or yellow coloring that matches local orchids. This insect both camouflages from predators and attracts pollinators, which it ambushes for food. ✨ #animals⚡#camouflage⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1246 · 22.01.2026 г., 18:11

🌎 The Indian leaf butterfly disguises itself as a dead leaf when at rest, with veins and brown patterns mimicking real foliage. When disturbed, it reveals bright blue and orange wings underneath—stunning colors that help startle predators. This butterfly is native to forests in South and Southeast Asia. ✨ #camouflage⚡#adaptation⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #378 · 21.07.2025 г., 18:22

🌎 The mimicry leaf insect looks exactly like a real leaf, down to brown spots that resemble decay. This remarkable disguise protects it from hungry predators by blending perfectly into the forest floor. ✨ #insects⚡#camouflage⚡#adaptation 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #728 · 11.09.2025 г., 13:22

🌎 Peacock spiders from Australia show off bold, iridescent colors during their unique courtship dances. Males raise flaps on their abdomen that resemble tiny rainbows to attract females. Over 80 species have been identified, each with distinct colors and patterns. ✨ #animals⚡#camouflage⚡#spiders 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #447 · 28.07.2025 г., 14:22

🌎 In Madagascar, the leaf-tailed gecko uses its flattened body and jagged skin edges to blend perfectly with tree bark, becoming nearly invisible to predators. This camouflage is so advanced that even experienced biologists often miss spotting them during the day. ✨ #reptiles⚡#camouflage⚡#Madagascar 👉subscribe Interesting Planet

12
ПретходнаСтраница 1 од 2Следна