Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
🇧🇩#Bangladesh – Il National Citizen Party (#NCP), fondato dagli studenti Gen Z che hanno portato alla caduta dell’ex premier Sheikh #Hasina, si coalizzerà con i partiti islamisti in vista delle elezioni di febbraio. Diversi dirigenti e candidati riformisti si sono dimessi in seguito alla decisione che potrebbe portare il clero islamico al governo.
@UltimoraPolitics24
News: Former #Sudan PM Hamdok says Islamist factions major obstacle to ending war
Abdalla Hamdok, Former Sudanese Prime Minister and head of the Somoud civilian coalition, has said Islamist factions linked to Sudan’s former ruling party are among the main obstacles to ending the country’s nearly three-year civil war, according to a report by Abu Dhabi-based newspaper The National.
Speaking to the newspaper on the sidelines of the 39th African Union summit in #Addis_Abeba, Hamdok said Islamist groups and the National Congress Party (#NCP) — the political party of ousted president Omar Al Bashir — remains key actors resisting peace initiatives and efforts to reach a broader national consensus.
He also criticized Sudan’s army chief, Gen Abdel Fattah #Al_Burhan, for insisting on a military solution to defeat the rival Rapid Support Forces (#RSF). Al Burhan has publicly ruled out peace....
https://web.facebook.com/AddisstandardEng/posts/pfbid02qycixQfoRJLo5F9EWtxgsymfNbxMqUa9D4Qquz6X3DjfUBUFxig1b3xTGb3MzEHHl
🇧🇩#Bangladesh – Oggi oltre 120 milioni di cittadini sono stati chiamati alle urne per rinnovare i 350 seggi del Parlamento, le prime elezioni dopo la deposizione della premier Sheikh #Hasina e la messa al bando della Lega Awami. Si sono sfidati il Partito Nazionalista Bengalese (#BNP) di Tarique #Rahman (rientrato dall’esilio a Londra dopo 17 anni), di centro-destra, per la liberalizzazione dell’economia, vicino alla classe media e all’esercito, e la coalizione guidata dal partito islamista Jamaat-e-Islami (#Jamaat) di Shafiqur #Rahman, che punta a introdurre la sharia nel Paese. La coalizione include il Partito Nazionale dei Cittadini (#NCP), fondato dai leader delle proteste studentesche, ma l’alleanza con gli islamisti è stata fortemente contestata da donne, laici e minoranza indù che avevano sostenuto le proteste. Risultati nelle prossime ore.
@UltimoraPolitics24