Метод строки split() разделяет строку на несколько строк по указанному символу
>>> "a_b_c".split('_')
['a', 'b', 'c']
Можно указать максимальное количество разделений
>>> "a_b_c".split('_', 1)
['a', 'b_c']
Или резать с другой стороны с помощью rsplit() (right split)
>>> "a_b_c".rsplit('_', 1)
['a_b', 'c']
А что будет если оставить аргументы пустыми?
>>> "a_b_c".split()
['a_b_c']
Получаем список с одним элементом, потому что по умолчанию используется пробельный символ.
>>> "a b c".split()
['a', 'b', 'c']
То есть это равнозначно такому вызову?
>>> "a b c".split(" ")
['a', 'b', 'c']
Кажется да, но нет! Давайте попробуем добавить пробелов между буквами
>>> "a b c".split(" ")
['a', '', '', 'b', '', '', 'c']
И вот картина уже не так предсказуема 😕
А вот что будет по умолчанию
>>> "a b c".split()
['a', 'b', 'c']
Всё снова красиво! 🤩
По умолчанию в качестве разделителя используется любой пробельный символ, будь то табуляция или новая строка. Включая несколько таких символов идущих подряд. А также игнорируются пробельные символы по краям строки.
>>> "a\t b\n c ".split()
['a', 'b', 'c']
Аналогичный способ можно собрать с помощью регулярного выражения. Но пробелы по краям строки придется обрабатывать дополнительно.
>>> import re
>>> re.split(r"\s+", ' a b c '.strip())
['a', 'b', 'c']
Здесь тоже можно указать количество разделений
>>> re.split(r"\s+", 'a b c', 1)
['a', 'b c']
А что если мы хотим написать красиво, то есть split() без аргументов, но при этом указать количество разделений? В этом случае первым аргументом передаём None
>>> "a\n b c".split(None, 1)
['a', 'b c']
Данный метод не учитывает строки с пробелами, взятые в кавычки
'a "b c" '.split()
['a', '"b', 'c"']
Но для таких случаев есть другие способы.
#tricks#basic
#lua
99 is an alpha Neovim plugin for skilled coders that streamlines AI requests using OpenCode. Install via Lazy with the given Lua config, set keymaps like `<leader>9f` to fill functions, `<leader>9v` for visual AI edits (visual mode only), and `@` for cmp skill autocompletion from custom SKILL.md rules or AGENT.md files. View logs with `:lua require("99").view_logs()`. It boosts your workflow by keeping AI help inside Neovim for fast, restricted code generation without leaving your editor.
https://github.com/ThePrimeagen/99
#lua
OTClient Redemption is a flexible and complete alternative client for the game Tibia, designed to work with OTServ servers. It uses LUA scripting and CSS-like syntax for easy customization of the game interface, allowing you to create new mods and extend features. Written in modern C++20, it supports advanced graphics, sound, multi-language, and mobile platforms through OpenGL. It offers many features like shaders, animated textures, transparency, and an in-game LUA terminal. This client improves performance with multi-threading and garbage collection, and adapts smoothly to server latency for better gameplay. You benefit by having a customizable, high-performance client that enhances your Tibia experience and supports modding and mobile use.
https://github.com/mehah/otclient
#lua
Path of Building 2 is a free offline tool for planning your Path of Exile 2 character builds. It helps you calculate your damage, defenses, life, mana, and other stats accurately by including buffs, auras, and enemy resistances. You can plan your passive skill tree, add and toggle skills, and manage items by importing them directly or crafting custom gear. It supports minions, party play, and sharing builds with others. This tool saves you time and effort by showing exactly how changes affect your character, helping you create strong, optimized builds before playing. It updates automatically and works offline for convenience.
https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2
#lua#github#neovim
Octo.nvim lets you edit and review GitHub issues, pull requests, and discussions right in Neovim. Just open with commands like `//github.com/user/repo/issues/1` or `w` to sync changes instantly. Add reactions, labels, assignees, or reviewers easily. This saves time by keeping all GitHub work in your editor—no browser switching—boosting productivity for developers managing repos.
https://github.com/pwntester/octo.nvim