Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 Perched atop a limestone cliff, the Italian town of Civita di Bagnoregio is slowly crumbling away as erosion eats at its base. Only about 12 people reside year-round, and the settlement is accessible by a pedestrian bridge spanning a deep valley. ✨
#geography⚡#architecture⚡#erosion
👉subscribe Interesting Planet
👉more Channels
🌍 Some coastlines in Alaska lose up to 20 meters of land each year from a mix of sea ice loss, stronger storms, and thawing ground, making it one of the fastest-eroding coastlines worldwide. ✨
#erosion⚡#coastline⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Some sea stacks—towering rock columns near coastlines—form when waves erode cliffs, leaving only isolated pillars. Ireland’s Dun Briste sea stack stands 50 meters above the Atlantic. ✨
#coastline⚡#erosion⚡#geology⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In some places, rising sea levels have pushed salty ocean water far inland, turning once-fresh coastal farmland into wetlands and forcing communities to change how and where they grow crops. ✨
#erosion⚡#sea-level ⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In some places, coastal cliffs are vanishing so quickly that entire villages have moved inland within a single generation, as sea level rise and stronger storms speed up the erosion. ✨
#erosion⚡#coastlines⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In some low-lying Pacific islands, entire villages have relocated inland as coastal erosion worsens from rising sea levels, erasing beaches and farmland within a single generation. ✨
#erosion⚡#sea-level ⚡#islands⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Rainwater can carve entire underground labyrinths in karst landscapes, creating vast networks of caves, tunnels, and sinkholes—some so deep and complex that new passages are still being found today. ✨
#caves⚡#karst⚡#erosion⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Coastal erosion is eating away cliffs and beaches so fast in some places that detailed maps need updating every year, with new shorelines appearing and disappearing before our eyes. ✨
#coastlines⚡#erosion⚡#mapping⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the last 30 years, parts of Louisiana’s coast have lost over 2,000 square kilometers of land to erosion and rising seas—an area bigger than many cities, disappearing into open water. ✨
#erosion⚡#sea-level ⚡#wetlands⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In some regions, sea level rise combines with sinking land, making coastal erosion even faster. This double impact is shrinking important wetlands and salt marshes much quicker than before. ✨
#erosion⚡#wetlands⚡#sea-level ⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Coastal erosion now removes up to 24 square meters of land per meter of shoreline in some parts of West Africa each year, forcing whole fishing villages to move further inland. ✨
#coastlines⚡#erosion⚡#sea-level ⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Satellite data shows that some coastlines have retreated by over 50 meters in just a decade, as rising sea levels and stronger storms rapidly reshape shores across the globe. ✨
#erosion⚡#sea-level ⚡#coastlines⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels