Ранее я делал серию постов про битовые операторы.
Вот вам ещё один наглядный пример как это используется в 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
Caramelized Onion Pasta
Ingredients:
Oven:
*300 g shallots
*300 g vegan cream cheese
*60 ml maple syrup
*200 g smoked tofu
*salt and pepper
*Oil as desired
Aside from that:
*350g pasta
*200 g dried tomatoes
*1 bunch of fresh wild garlic
*60 ml pasta water
#paste
@dishes
Rice Noodle Spring Salad
Ingredients:
*1 carrot
*100 g fresh red cabbage
*1/2 cucumber
*1/2 red onion
*1 mango
*250 g rice noodles
Peanut sauce:
*2 cm ginger
*2 cloves of garlic
*200 g peanut butter
*20 ml sesame oil
*50 ml maple syrup
*50 ml soy sauce
*150ml water
Toppings:
Chili flakes
Coriander, mint
peanuts
#paste
@dishes
You Need To Taste This Green Goddess Salad With Watermelon & Pasta
Ingredients:
*200 grams of watermelon
*100 grams of cucumber
*200 grams of pasta
Dressing:
*80 grams of spinach
*1/2 bunch basil
*1 clove of garlic
*1/2 onion
*50 grams of peas
*40ml oil
*25ml water
*1 tbsp vinegar
*1 tsp salt
*40 grams of walnuts
*juice of a lemon
*1 tbsp yeast flakes
*pinch of pepper
toppings:
Walnuts, Basil, Chili Flakes
#paste
@dishes
Pasta Alla Vodka with Pancetta🧀
Ingredients:
*350g. Rigatoni pasta (Can be replaced with penne pasta)
*2 Tbsp Olive oil
*150g. diced Pancetta
*2 Shallot onion, finely chopped
*3 Garlic cloves, finely chopped
*1/2 Tsp Red-Chilli flakes
*1/2 Tsp dried Oregano
*1/2 cup Vodka
*1 cup Tomato sauce
*1/4 cup Tomato paste with basil pesto
*2 cup Heavy cream
*1/4 cup Parmesan cheese, plus more for serving
*1 tablespoon roughly chopped fresh Basil
*2 tablespoons roughly chopped Italian Parsley
#paste
@dishes
ROASTED RED PEPPER PASTA! 🌶️
Ingredients:
* 400 g. Giant Fusilli Pasta
* 4 Red Bell Peppers
* 2 Shallot onion
* 1 head Garlic
* Olive oil
* 1 cup Heavy Cream
* Red chili flakes
* Italian herbs
* 1 tbsp Tomato paste
* 1 tbsp Butter
* Salt/Pepper
#paste
@dishes