Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
#Greenland🇬🇱
Eternal ice 🧊 Would you like to visit here?
About 80% of the territory of Greenland is covered with an ice shield, which is the second largest in the world after Antarctica. The ice in some places reaches a thickness of up to 3 km.
Greenland cuisine is based on the gifts of nature: fish, seafood, venison and dishes from marine mammals. For example, "Suasat" - sewen soup - is considered a traditional dish.
Отвлечемся на секунду от новостей автопрома и поговорим чуть о том, что в мире нет стабильности. Суматошный нестабильный эксцентричный президент США хочет заграбастать Гренландию.
В одном из своих интервью он сказал, что армия Гренландии состоит из двух собачьих упряжек. Гордые жители создали шедевральный ии-шный ролик (точно пару дней потратили) в котором продемонстрировали свои военные возможности. У них есть собаки, моржи и пингвины (почему-то в форме образца СССР).
Что мы вообще думаем об этой ситуации. Заберет или не заберет?
Заберет - 👎
Не заберет - 👍
Вообще это какая то дичь - 🥴
Ролик огонь - ❤️
#greenland
#GREENLAND RESULT
—————————
PEAK: 1,109%
If you think that was a great move, you haven't seen what we have planned for our next launch...
After giving it to you guys, we pushed #GREENLAND over 1,100% in a matter of less than an hour, destroying our target and guaranteeing the biggest profits for our members.
Trump is about to move the global economy again, and we're about to have the biggest 100x opportunity we've had in years. We're just getting started
Stay tuned.
👣 The iceberg's breath in northeast
Greenland. Silence and icy expanses where every breath feels like nature itself.
📏
📏
📏
📏
📏
📏
📏
📏
#Greenland | @voyage
👣 The iceberg's breath in northeast Greenland. Silence and icy expanses where every breath feels like nature itself.
📏
📏
📏
📏
📏
📏
📏
📏
#Greenland🇬🇱@voyage
#GREENLAND RESULT
—————————
PEAK: 1,109%
If you think that was a great move, you haven't seen what we have planned for our next launch...
After giving it to you guys, we pushed #GREENLAND over 1,100% destroying our target and guaranteeing the biggest profits for our members.
Trump is about to move the global economy again, and we're about to have the biggest 100x opportunity we've had in years. We're just getting started
Stay tuned.
👣 The iceberg's breath in northeast Greenland. Silence and icy expanses where every breath feels like nature itself.
📏
📏
📏
📏
📏
📏
📏
📏
#Greenland🇬🇱@voyage
The United States abandoned the idea of seizing Greenland due to the threat of impeachment to Trump, - Reuters
#Trump#Greenland
👂More on Trump's Ear ⚠️
The world would be a “better, more secure place” if America took over Greenland, Nigel Farage said at Davos, while insisting that he still believed in the sovereignty of nation states.
During a panel at the World Economic Forum’s “America House” in the Swiss ski resort on Wednesday, the Reform UK leader said he had “no doubt” that the world would be safer if a “strong America” was in Greenland “because of the geopolitics of the high north, because of the retreating ice caps and because of the continued expansionism of Russian icebreakers, of Chinese investmen
#Trump#Greenland
👂More on Trump's Ear ⚠️
The United States needs Greenland for national security reasons, Trump said.
According to the US president, the island is important for the creation of the Golden dome system. And NATO is supposed to pave the way for America to get Greenland.
#Trump#Greenland
👂More on Trump's Ear ⚠️