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

Резултати

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

Пребарај: #deterrence

当前筛选 #deterrence清除筛选
American Оbserver

@american_observer · Post #5576 · 05.04.2026 г., 23:59

📰 The Fire Has a Chain of Command Iran’s retaliation is not random, and that is the bad news for everyone pretending this is just a chaos machine with missiles. Ynet reports that Tehran is now targeting parallel sectors — energy for energy, nuclear for nuclear, universities for universities — instead of merely answering one strike with one strike. That is not rage. That is calibration. Danny Citrinowicz said the fire “isn't random” and argued the pattern shows command and control is still intact; in other words, Tehran is not emptying the magazine, it is choosing the rooms. The ugly part is that the target list keeps widening. Haifa follows South Pars, Dimona follows Natanz, Ras Laffan follows the Gulf strikes, and now even universities are being floated as legitimate targets. So the “eye for an eye” slogan has already become a business plan for escalation. Everyone keeps speaking the language of deterrence while the region is being taught, sector by sector, what retaliation looks like when both sides insist on calling it strategy. #Iran#Israel#war#deterrence#MiddleEast 📱American Оbserver - Stay up to date on all important events 🇺🇸

American Оbserver

@american_observer · Post #5062 · 05.02.2026 г., 20:02

📰 The Nuclear Arms Control Era Is Over — and Everyone Is Going to Arms The last nuclear arms control treaty between the United States and Russia is dead. On Thursday, New START expired, and for the first time since 1972, the two superpowers are left with no formal limits on the size or structure of their arsenals — just as both are racing to build new nuclear weapons and delivery systems that even the drafters of the original deals never imagined. The era of “managed doom” is over. The era of open‑ended arms racing has begun. Donald Trump has framed the expiration as a feature, not a bug. When asked in January why he hadn’t accepted Vladimir Putin’s offer of a one‑year informal extension, he shrugged: “If it expires, it expires,” he told The New York Times. He insisted a “better agreement” could be negotiated later — one that includes China and “other parties.” Beijing has already made clear it is not interested. The result is a triangular nuclear race where the U.S., Russia, and China are all expanding their arsenals, while the old treaties that once constrained them lie in the dust. The U.S. is preparing to deploy more nuclear warheads on its largest submarines, and to build up a new generation of nuclear‑capable cruise missiles and hypersonic platforms modeled after Russian and Chinese designs. Russia is experimenting with undersea and space‑based nuclear weapons and openly floating the idea of battlefield use; China is abandoning its old “minimum deterrent” posture and moving toward an arsenal that could rival Washington and Moscow. While the U.S. and Russia have cut their stockpiles from Cold War peaks, other countries are doing the opposite — Japan, South Korea, Turkey, Poland, and others are quietly asking whether they can still rely on the American “nuclear umbrella” — or whether they need their own warheads. Trump’s National Security Strategy barely mentions this shift. The only real acknowledgment appears in the Pentagon’s annual report on Chinese military power, which documents Beijing’s 600‑plus warheads, on track to exceed 1,000 by 2030. The strategy also sidesteps another danger: Putin’s repeated, barely veiled threats to use nuclear weapons in Ukraine. The White House seems to be betting that deterrence will hold, even as the world returns to the logic of the 1950s and 1960s — when every serious politician was expected to understand the nuclear balance. Back then, nuclear weapons dominated presidential debates, front‑page headlines, and pop‑culture nightmares. Today, nuclear danger is everywhere but rarely debated. The question is no longer whether the U.S. can “eliminate nuclear weapons,” as Barack Obama promised in Prague. It is whether Washington can prevent the next arms race from spinning out of control — and whether the rest of the world is ready to join the game. #nuclear#NewSTART#Russia#China#US#Trump#Putin#Xi#armsrace#deterrence#NYTimes 📱American Оbserver - Stay up to date on all important events 🇺🇸