TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #146 · 16 сеп.

Функция sub в regex может принимать функцию в качестве аргумента repl. 📄 Из документации: If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string. То есть для каждого совпадения будет вызвана функция для вычисления замены вместо замены на одну и ту же строку для всех совпадений. Иными словами, для замены разных совпадений на разные строки не потребуется запускать re.sub() много раз для каждой строки замены. Достаточно определить функцию, которая вернёт строку для каждого из совпадений. Описание слишком запутанное🤔, давайте лучше рассмотрим на простом примере: Создаем карту замены. То есть какие строки на какие требуется менять. remap = { 'раз': '1', 'два': '2', 'три': '3', 'четыре': '4', 'пять': '5', } Пишем функцию поиска строки для замены. Единственным аргументом будет объект re.Match. Используя данные этого объекта мы вычисляем замену on-the-fly! def get_str(match: re.Match): word = match.group(1) return remap.get(word.lower()) or word Пример текста. text = '''Раз Два Три Четыре Пять Вместе будем мы считать Пять Четыре Три Два Раз Мы считать научим вас ''' Теперь запускаем re.sub и вместо строки замены (repl) подаём имя функции. (Данный паттерн ищет отдельные слова в тексте) >>> print(re.sub(r'(\w+)', get_str, text)) 1 2 3 4 5 Вместе будем мы считать 5 4 3 2 1 Мы считать научим вас Думаю, достаточно наглядно 🤓 #libs#regex

Hashtags

Резултати

Пронајдени 9 слични објави

Пребарај: #piyush

当前筛选 #piyush清除筛选
Pensive|

@PensivePost · Post #5015 · 23.03.2021 г., 10:41

When I was old I'd never chase peace, Now I can't live without this. When I was old I never thought I'll miss, Now everything is temporary still I seek. Used to cry when someone leaves me alone, Now me, myself and I love to stay at home. Used to cry when someone shows me the ghost, Now I don't know how to cry every day I see the living ghost in the people. I always live with the right people, who might care! If anybody wants to prove me wrong, I say “I think you are right there”. Don't let the world falls you down, you're doin alright, damn! #review#piyush

Pensive|

@PensivePost · Post #5001 · 15.03.2021 г., 09:59

Baby you can't ruin all the beautiful things Stop doing all these suitable mood swings Why did you think, That way. Sometime mind fucked up And the heart has to pay. I don't want to hate you Please don't make me to say it. We should forget bout us And shall pretend like we don't remember each other name. You were behind the fame and I understand. I was in pain but You didn't understand. #piyush#review

Pensive|

@PensivePost · Post #5013 · 22.03.2021 г., 10:27

Your world what was so busy So I left alone and that wasn't easy Our love didn't leave any meaning Then I called you and you keep it on ringing Now my heart can't stop singing My mind can't stop thinking 'Bout you I thought my friend would leave me, but not you I hope you too wanted the same thing Love, lust and fam thing Our future is now too far Am I blind? Why don't I can't see? Can't see, can't see, can't see.. ? Anymore.. Don't know 'bout those First, they love and then leave What made you by leaving them broke? #piyush#poetry#review

Pensive|

@PensivePost · Post #4878 · 06.02.2021 г., 14:27

Spectrum of love I had once affected from love We were one, now it's just get separate by move No one tried to prove Now we aren't into.., Love. But still checking up on each other's. Maybe we still don't want to get lose That was best life, when I had choose.., Her. Now it's getting worse and I can't do.., Anything. Stucked up on penny things, You and me had fucked up everything. Me and her, had dreams. It was fucked up ever since. #review#piyush#verse

Pensive|

@PensivePost · Post #4872 · 04.02.2021 г., 18:06

Why it's feels so alone? Maybe cause of I didn't hear my fav songs It's night and it's so dark It's feeling like I'm lost When this night will end? Stop living in my head! What if I stay calm? And what if you stay with me? There are thousands of words to say And you are not here to listen to me One day you would come at any reason for me And one day I'll be gone for many reasons and you won't see that coming.. #review#piyush#verse

Pensive|

@PensivePost · Post #4862 · 03.02.2021 г., 11:11

She just want to be alright, Even things are not all right, She's now crying like all night, She chooses darkness so she lose light. Now even god wants to know, who's right ? I didn't do anything wrong and idk if I have did maybe, No one knows how much I need you my baby, Again! You left me but when will this pain? You got yourself outta my life and I'm still in that lane. Sometime true love dies and no one gives a damn, Tell me after broking me what did you gain? #review#piyush#verse

Pensive|

@PensivePost · Post #4856 · 02.02.2021 г., 17:17

She cried and said “why you want to control me?” I cried and said “it doesn't make me lonely.” She said is love isn't there to make we us? I said that's right but what bout lust? She still think that I was hiding something And than she left me saying you share nothing Now she miss me too Losing controlling too She thought I was fake But now who left true? #verse#review#piyush

Pensive|

@PensivePost · Post #4966 · 27.02.2021 г., 19:37

She was drunk and lonely Alone in the city maybe that's why she don't know me Writing bout her maybe that's made her know me Hooked up with her cause she was horny She didn't said any word but when I left she said wish you'd met me before I just saw in her eyes and felt like she want more Her body wanting me but she couldn't said any word Maybe she don't want to get addict or maybe she don't want to do this anymore Her weight was much heavy but at that time, I made her feel low She said wanting this so hard, waiting from the months Tell me how you get good at this ? now I can't satisfy at once I just started from removing clothes and slowly her body started gettin burn Pleasure come with pain though but she was having fun Leg was stucked with her pants but it looks like she wanted to run Or maybe she wanted the one who won't run and drive her crazy And later, she found me and I found her, no one is between us (Erotic breathing and saying) 'Amazing'. #review#piyush#fictionalstory

Pensive|

@PensivePost · Post #4855 · 02.02.2021 г., 17:05

She cried and said “why you want to control me?” I cried and said “it doesn't make me lonely.” She said is love isn't there to make we us? I said that's right but what bout lust? She still think that I was hiding something And than she left me saying you share nothing Now she miss me too Losing controlling too She thought I was fake But now who left true? #review#verse#piyush#pease