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

Резултати

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

Пребарај: #nuclearprogram

当前筛选 #nuclearprogram清除筛选
Crypto M - Crypto News

@CryptoM · Post #65155 · 11.04.2026 г., 13:17

🚀 U.S.–Iran Discussions Begin as Vice President Vance Leads Talks in Islamabad Key Takeaways JD Vance is leading high-stakes talks with Iran in Islamabad.Negotiations aim to stabilize the ceasefire and end the conflict.Talks are indirect and mediated by Pakistan amid deep mistrust.Key issues include Strait of Hormuz, sanctions, and nuclear program. Talks Officially Underway Discussions involving the United States and Iran have officially begun in Islamabad, with JD Vance heading the US delegation. The negotiations are part of a broader effort to extend a fragile ceasefire and potentially move toward a longer-term resolution of the conflict. Pakistan Acting as Mediator The talks are being hosted and mediated by Pakistan, which has played a central role in facilitating communication between both sides. Meetings are taking place under tight security conditionsDelegations are engaging through indirect channels, though direct talks may occurPakistani officials are coordinating between both sides to push toward progress High-Stakes Agenda Key topics under discussion include: Reopening the Strait of Hormuz (critical for global oil supply)Potential sanctions relief for IranLimits on Iran’s nuclear programBroader regional stability and ceasefire enforcement Tensions and Mistrust Remain High Despite the start of talks, major disagreements persist: Iran has set conditions, including halting certain military actionsThe US has maintained a firm stance and warned against delaysBoth sides remain cautious, reflecting deep geopolitical mistrust #USIranTalks#JDVance#Islamabad#PakistanMediating#Ceasefire#StraitOfHormuz#Sanctions#NuclearProgram#RegionalStability#GeopoliticalTensions#DiplomaticNegotiations#HighStakes