Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🌎 The giant Trilithon stones at Stonehenge in England each weigh about 25 tons and were transported from over 30 kilometers away. These standing stones date to around 2500 BCE and were arranged in a unique horseshoe pattern that still stands today. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Towering over the Peruvian desert, the megalithic complex of Sacsayhuamán features walls made from stone blocks weighing up to 200 tons each. These blocks fit so precisely that even a piece of paper cannot slide between them. ✨
#archaeology⚡#history⚡#megaliths
👉subscribe Interesting Planet
👉more Channels
🌎 Rising above the Jordanian desert, the prehistoric megaliths known as “desert kites” are vast stone structures with funnel-shaped walls stretching for hundreds of meters. Archaeologists have identified more than 6,000 desert kites across the Middle East, mostly built between 7000 BCE and 2000 BCE, likely used to trap wild animals. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Looming over the English Channel, the Carnac stones on Guernsey form a megalithic passage grave known as Le Déhus. Built around 3500 BCE, it features a massive stone chamber and carved capstones. The longest stone weighs nearly 10 tons and the site is aligned to the sunrise at midsummer. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Hidden in the forests of western Russia, the megalithic dolmens of the Caucasus feature massive stone chambers built from precisely carved granite slabs. Some of these structures date back over 5,000 years and weigh more than 15 tons each, puzzling archaeologists with their construction methods and unknown cultural origins. ✨
#megaliths⚡#archaeology⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Stonehenge in England features massive upright stones called sarsens, each weighing up to 25 tons. Built around 2500 BCE, the monument’s purpose is still debated, but recent studies found the stones were transported from over 25 kilometers away on wooden sledges and rollers. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 The megalithic site of Carnac in Brittany, France, contains over 3,000 standing stones arranged in rows stretching more than 4 kilometers. Erected between 5000 and 3300 BCE, these granite monoliths are among the world’s largest collections of ancient stone alignments. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 In southern England, the ancient monument of Silbury Hill rises 40 meters and was built over 4,000 years ago using chalk and earth. Archaeologists have never found burials, temples, or inscriptions inside, leaving its purpose mysterious. Silbury Hill is the largest man-made prehistoric mound in Europe. ✨
#archaeology⚡#mystery⚡#megaliths
👉subscribe Interesting Planet
👉more Channels
🌎 The “Plain of Jars” in Laos is scattered with thousands of massive stone jars, some weighing over 10 tons. Archaeologists date them to the Iron Age, around 500 BCE to 500 CE, but their purpose—possibly for funerary or storage rites—remains uncertain. Over 90 jar sites have been documented across the region. ✨
#archaeology⚡#megaliths⚡#mystery
👉subscribe Interesting Planet
👉more Channels
🌎 The Baalbek Trilithon in Lebanon features three enormous stone blocks, each weighing around 800 tons, forming the base of the Roman Temple of Jupiter. These stones are among the heaviest ever used in ancient construction, and were quarried and moved more than 800 meters from their original location. ✨
#archaeology⚡#megaliths⚡#engineering
👉subscribe Interesting Planet
👉more Channels
🌎 Towering in the remote Pacific, the moai statues of Easter Island were carved from volcanic rock between 1400–1650 CE. The heaviest moai weighs around 82 tons, showcasing the islanders’ exceptional engineering with limited technology. ✨
#megaliths⚡#archaeology⚡#engineering
👉subscribe Interesting Planet
👉more Channels
🌎 Rising from the Lebanese landscape, the megalithic stones of Baalbek include the Stone of the Pregnant Woman—one of the world’s largest quarried stones at over 1,000 tons. Ancient builders moved and stacked these limestone giants with such precision that modern engineers still debate the techniques used. ✨
#archaeology⚡#megaliths⚡#engineering
👉subscribe Interesting Planet