@MyGovCoronaNewsdesk · Post #13060 · 19.01.2024 г., 06:26
Your voice matters in shaping Viksit Bharat @ 2047. Share your dreams for a thriving India on #MyGov. Join the journey at: https://innovateindia.mygov.in/viksitbharat2047/
Hashtags
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
Пребарај: #mygov
@MyGovCoronaNewsdesk · Post #13060 · 19.01.2024 г., 06:26
Your voice matters in shaping Viksit Bharat @ 2047. Share your dreams for a thriving India on #MyGov. Join the journey at: https://innovateindia.mygov.in/viksitbharat2047/
Hashtags
@MyGovCoronaNewsdesk · Post #12981 · 22.12.2023 г., 13:43
👆Just 10 days until we step into 2024! Join #MyGov on an exclusive journey presenting '10 Infra Magic of New India' in the final countdown of 2023. Don't miss out!
Hashtags
@MyGovCoronaNewsdesk · Post #12690 · 10.05.2023 г., 07:41
Test your knowledge on India's journey towards Swaraj with the Swaraj Quiz Episode 39 on #MyGov. Visit https://quiz.mygov.in/quiz/swaraj-quiz-episode-39/ to learn about the inspiring leaders and events that shaped our nation's history.
Hashtags
@MyGovCoronaNewsdesk · Post #12657 · 02.05.2023 г., 06:33
Calling all aspiring tech entrepreneurs🧑💻🧑💻 Join the Chunauti 5.0 program by #MyGov and take a step towards a stronger and self-reliant India. Apply NOW and be a part of the innovative startup ecosystem. Visit: https://www.mygov.in/task/chunauti-50-%E2%80%93-call-application/
Hashtags
@MyGovCoronaNewsdesk · Post #12609 · 25.04.2023 г., 08:38
Oral health is crucial for overall well-being! Join the Oral Health campaign by #MyGov to spread awareness and promote healthy dental practices. Visit: https://mygov.in/campaigns/oral-health/?utm_source=mygov_campaign
Hashtags
@MyGovCoronaNewsdesk · Post #12562 · 18.04.2023 г., 10:40
Spread positivity and laughter with your creativity! Participate in the खुलकर जियो Khul Kar Muskurao meme contest on #MyGov and win exciting prizes. Visit: https://www.mygov.in/task/khulkar-jieo-khulkar-muskurao-meme-contest/
Hashtags
@MyGovCoronaNewsdesk · Post #12560 · 18.04.2023 г., 05:04
Congratulations to the winners of #MyGov's New India Quiz for March 🏆🏆 Your knowledge of India is impressive! Keep learning and exploring the diverse cultures and traditions of our incredible nation. Visit: https://blog.mygov.in/winner-announcement-blog-for-mygovs-new-india-quiz-march-month-mann-ki-baat/
Hashtags
@MyGovCoronaNewsdesk · Post #12557 · 17.04.2023 г., 08:35
Show your creativity and spread awareness about oral health through your writing skills! Participate in the Poem Writing Competition on #MyGov. Visit: https://www.mygov.in/task/poem-writing-competition-oral-health/
Hashtags
@MyGovCoronaNewsdesk · Post #12555 · 16.04.2023 г., 10:31
Lights, Camera, Smile! Showcase your filmmaking skills and spread positivity with 'खुलकर जियो Khul Kar Muskurao short film contest' on #MyGov. Visit https://www.mygov.in/task/khulkar-jieo-khulkar-muskurao-short-film-contest/ for more details
Hashtags
@mygovcoronanewsdesk · Post #12354 · 19.03.2023 г., 08:02
Capture the Beauty of Ladakh with your lens. Participate in Photography Contest on #MyGov Visit: https://ladakh.mygov.in/task/capture-beauty-ladakh-photography-contest
Hashtags
@mygovcoronanewsdesk · Post #12338 · 16.03.2023 г., 15:22
Capture the Beauty of Ladakh with your lens. Participate in Photography Contest on #MyGov Visit: https://ladakh.mygov.in/task/capture-beauty-ladakh-photography-contest
Hashtags
@mygovcoronanewsdesk · Post #12336 · 16.03.2023 г., 09:56
#MyGov now reaches the breathtaking landscapes of Ladakh to foster greater citizen engagement & empowerment Visit: ladakh.mygov.in
Hashtags