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

Резултати

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

Пребарај: #bsd

当前筛选 #bsd清除筛选
Solidot 纯净版

@SolidotR · Post #4520 · 11.02.2026 г., 14:35

NetBSD 11.0 RC1 释出 #BSD NetBSD 项目释出了 NetBSD 11.0 的首个 RC 版本。主要新特性包括:支持 64 位 RISC-V 平台;增强对 POSIX.1-2024 和 C23 编程接口标准的兼容性;增强对 compat_linux(8) 中 Linux 系统调用的支持;初步支持高通骁龙 X Elite 平台;改进 npf(7) 防火墙;新 MICROVM kernel for x86,专为实现极速虚拟机启动设计,在 2020 年时代 x86 CPU 上启动仅需 10 毫秒;新 virt68k,等等。 https://www.netbsd.org/releases/formal-11/NetBSD-11.0.html

Hashtags

GitHub Trends

@githubtrending · Post #14667 · 03.05.2025 г., 12:30

#rust#bsd#gpu#linux#macos#opengl#rust#terminal#terminal_emulators#vte#windows Alacritty is a fast, cross-platform terminal emulator that uses OpenGL for smooth performance, works on BSD, Linux, macOS, and Windows, and offers customizable settings while keeping things simple. It’s lightweight, integrates well with tools like window managers or terminal multiplexers, and is already reliable enough for daily use despite being in beta, making it ideal for users who want speed and flexibility without unnecessary features. https://github.com/alacritty/alacritty

GitHub Trends

@githubtrending · Post #15567 · 17.03.2026 г., 11:30

#cplusplus#apple_silicon#bsd#c_plus_plus#cmake#floss#game#gplv2#json#linux#lua#macos_app#python#strategy#windows Widelands is a free, open-source real-time strategy game like Settlers II, where you lead a small clan to build roads, gather resources like wood and gold, manage four unique tribes, trade, or fight in single-player campaigns and multiplayer. Download it easily for Windows, Mac, or Linux, or compile from source with simple scripts and tools like CMake on various systems. This lets you enjoy deep, replayable empire-building fun at no cost, anytime with friends or AI. https://github.com/widelands/widelands

GitHub Trends

@githubtrending · Post #15000 · 27.07.2025 г., 12:00

#markdown#android#bsd#cheatsheet#cheatsheets#command_line#console#documentation#examples#hacktoberfest#help#linux#macos#man_page#manpages#manual#osx#shell#terminal#tldr#windows The tldr-pages project offers simple, easy-to-understand help pages for command-line tools, focusing on practical examples rather than long, complex manuals. It’s great if you’re new to the command line or forget command options, as it shows the most useful commands clearly. You can access these pages through various clients or online without installing anything. This saves you time and frustration by giving quick, clear guidance on common tasks, making it easier to learn and use command-line tools effectively. Plus, you can contribute by adding or improving pages yourself. This helps you and others get fast, practical help with commands[1][4]. https://github.com/tldr-pages/tldr