Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в Python в модуле re.
Чтобы указать флаг для компилятора нам надо указать его после передаваемой строки. Например, добавляем флаг для игнорирования переноса строки.
pattern = re.compile(r"(\w+)+")
words = pattern.search(text, re.DOTALL)
А как указать несколько флагов? Ведь явно будут ситуации когда нам потребуется больше одного. Кто читал посты по битовые операторы уже понял как.
pattern.search(text, re.DOTALL | re.VERBOSE)
А теперь смотрим исходники, что находится в этих атрибутах?
Не удивительно, степени двойки. Почему? Потому что каждое следующее значение это сдвиг единицы влево.
>>> for n in [1, 2, 4, 8, 16, 32, 64, 128, 256]:
>>>
print(bin(n))
0b1
0b10
0b100
0b1000
0b10000
0b100000
0b1000000
0b10000000
0b100000000
Чтобы было понятней, давайте напишем тоже самое но иначе, добавим ведущие нули:
000000001
000000010
000000100
000001000
000010000
000100000
001000000
010000000
100000000
Не понятно что тут происходит? Читай три поста про битовые операторы начиная с этого ➡️https://t.me/pythonotes/45
В общем, это пример применения побитовых операций в самом Python.
Теперь вы знаете Python еще немного лучше)
#tricks#regex#libs
🌎 In the Norwegian Arctic, the town of Longyearbyen bans dying at home, as bodies can't decompose in permafrost. Residents who are terminally ill must travel to the mainland. This small settlement is also the northernmost town with over 1,000 people. ✨
#arctic⚡#settlements⚡#permafrost
👉subscribe Interesting Planet
👉more Channels
🌎 The Siberian permafrost preserves ice age seeds for tens of thousands of years. Scientists have revived ancient plants, like Silene stenophylla, from seeds frozen over 30,000 years ago—proving some life can return after millennia in the deep freeze. ✨
#permafrost⚡#botany⚡#revival
👉subscribe Interesting Planet
🌎 Norilsk, Russia, is a city built above the Arctic Circle and is so remote that it’s closed to most foreigners. Founded in 1935 for nickel mining, it endures harsh winters with temperatures as low as −55°C. Norilsk is one of the largest cities in continuous permafrost and has no rail or road connection to the rest of Russia. ✨
#Norilsk⚡#Arctic⚡#permafrost
👉subscribe Interesting Planet
🌍 Some tundra soils contain buried ice wedges that can be thousands of years old. When permafrost thaws, these ancient ice wedges melt, creating strange sinkholes called "thermokarst." ✨
#permafrost⚡#tundra⚡#landscape⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 In tundra landscapes, some mosses and lichens can survive temperatures below –50°C and continue to photosynthesize under snow, making them some of the Earth’s hardiest plants. ✨
#tundra⚡#permafrost⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the far north, frozen permafrost soils hide ancient bacteria and seeds that can survive for thousands of years—emerging only when the tundra thaws after centuries of deep freeze. ✨
#permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the Siberian tundra, permafrost preserves massive underground "ice wedges" that crack open each winter and refill with meltwater every spring, leaving polygon patterns visible from above. ✨
#permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Some tundra ponds form when summer sun thaws just the surface of permafrost, creating seasonal lakes that vanish each year. These ponds support bursts of life in otherwise frozen landscapes. ✨
#tundra⚡#permafrost⚡#arctic⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the Arctic tundra, some permafrost layers are over 1,500 meters thick—deeper than most skyscrapers are tall. This frozen ground stores ancient DNA from plants and animals tens of thousands of years old. ✨
#permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In some Arctic tundra areas, ancient animal tracks remain frozen in permafrost for thousands of years. When the ground thaws, these footprints reappear, revealing hidden stories of past wildlife. ✨
#permafrost⚡#tundra⚡#Arctic⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌎 Every summer in Siberia, mysterious craters known as "Yamal holes" appear in the Arctic tundra. These giant pits, sometimes 20 meters wide, form when underground methane gas builds pressure and violently explodes through permafrost. Scientists have identified at least 17 such craters since 2014, linking them to warming temperatures and melting ice. ✨
#permafrost⚡#methane⚡#explosions
👉subscribe Interesting Planet
👉more Channels
🌍 In parts of Siberia, thawing permafrost can trigger sudden ground collapses called “thermokarst.” These sinks reshape the tundra and can swallow trees or create lakes almost overnight. ✨
#permafrost⚡#tundra⚡#landforms⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels