✂️ 列表截取(取第 N 到 M 项、前 N 项、Python 切片)Slice a List
从列表中截取需要的部分:按位置范围取第 N 到第 M 项(从 1 开始,负数表示倒数第几项),取前 N 项或后 N 项,每隔 N 项取一项,或直接使用 Python 切片语法 start:end:step(支持负数和倒序)。自动识别换行、逗号等分隔符,输出可保持原分隔符或每行一项。适合抽样、分页、提取数据片段和学习 Python 切片,数据在本地处理。Take just the part of a list you need: items N to M by position (counting from 1; negative numbers count from the end), the first or last N items, every Nth item, or Python slice syntax start:end:step (negative values and reverse order included). New lines, commas and other separators are detected automatically, and the output can keep the original separator or put one item per line. Handy for sampling, paging, pulling out chunks of data and learning Python slices. Processed locally.
使用说明与常见问题How-to & FAQ
「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」是什么?What is the Slice a List tool?
从列表中截取需要的部分:按位置范围取第 N 到第 M 项(从 1 开始,负数表示倒数第几项),取前 N 项或后 N 项,每隔 N 项取一项,或直接使用 Python 切片语法 start:end:step(支持负数和倒序)。自动识别换行、逗号等分隔符,输出可保持原分隔符或每行一项。适合抽样、分页、提取数据片段和学习 Python 切片,数据在本地处理。Take just the part of a list you need: items N to M by position (counting from 1; negative numbers count from the end), the first or last N items, every Nth item, or Python slice syntax start:end:step (negative values and reverse order included). New lines, commas and other separators are detected automatically, and the output can keep the original separator or put one item per line. Handy for sampling, paging, pulling out chunks of data and learning Python slices. Processed locally.
如何使用「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」?How do I use the Slice a List tool?
在「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」中,把内容粘贴或输入到上方输入框,按需设置「输入分隔符」、「自定义」、「截取方式」、「从第几项」、「到第几项」,结果会实时显示在下方,点击「复制结果」即可复制。In the Slice a List: Paste or type into the input box, adjust "Input separator", "Custom", "Slice", "From item", "To item"; the result appears below instantly — click "Copy result" to copy it.
位置是从 0 还是从 1 开始?Do positions start at 0 or 1?
“第 N 到 M 项”从 1 开始数,并且包含两端:第 2 到 4 项就是第 2、3、4 项;负数表示倒数,-1 是最后一项,-2 是倒数第二项;超出列表长度的部分会自动截断。只有“Python 切片”模式按 Python 规则从 0 开始、不包含结束位置。Items N to M counts from 1 and includes both ends, so items 2 to 4 are the 2nd, 3rd and 4th. Negative numbers count from the end: -1 is the last item and -2 the one before it. Anything past the end of the list is simply cut off. Only Python slice mode counts from 0 and excludes the end position, following Python's rules.
Python 切片怎么写?How do I write a Python slice?
格式是 start:end:step,三部分都可以省略:1:4 取索引 1、2、3;:3 取前 3 项;-3: 取最后 3 项;::2 每隔一项取一项;::-1 把整个列表倒过来;4:1:-2 从索引 4 倒着每隔一项取到索引 2。只写一个数字(如 0 或 -1)表示取那一项。结果与 Python 的 list[start:end:step] 完全一致。The form is start:end:step, and any part can be left out: 1:4 takes indices 1, 2 and 3; :3 the first three; -3: the last three; ::2 every other item; ::-1 reverses the whole list; 4:1:-2 goes backwards from index 4 in steps of two, stopping before index 1. A single number (such as 0 or -1) takes just that item. Results match Python's list[start:end:step] exactly.
分隔符是怎么自动识别的?How is the separator detected automatically?
“自动识别”按以下顺序判断:有换行就按行分隔,否则依次检查 Tab、分号、逗号(含中文逗号和顿号)、竖线,最后才是空格。用逗号、分号或 Tab 分隔时支持 CSV 式的双引号,例如 "北京, 中国" 会被当作一项。需要其他符号时选择“自定义”,可用 \n 和 \t 表示换行和 Tab。输出沿用原来的分隔符(包括自定义分隔符和中文逗号),含分隔符的项会重新加上双引号;空行默认忽略,不算作项目。Auto-detect works in this order: if there are line breaks, each line is an item; otherwise it checks for tabs, semicolons, commas (including the Chinese comma and enumeration comma), pipes and finally spaces. With comma, semicolon or tab separators, CSV-style double quotes are honoured, so "Paris, France" counts as one item. Choose Custom for anything else; \n and \t stand for a new line and a tab. The output keeps the original separator (including a custom one or the Chinese comma), items that contain the separator are quoted again, and blank lines are ignored by default.
处理大段文本会卡吗?Can it handle long text?
「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」在浏览器中直接处理,几 MB 以内的文本通常瞬间完成;文本不会离开你的设备。The Slice a List runs in your browser; text up to a few MB is usually processed instantly and never leaves your device.
「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」免费吗?需要注册吗?Is the Slice a List free? Do I need an account?
「列表截取(取第 N 到 M 项、前 N 项、Python 切片)」完全免费,无需注册或安装,打开网页即可使用,手机和电脑都能用;输入的内容只在你的浏览器本地处理。The Slice a List is completely free with no sign-up or install and works on phones and desktops; what you enter is processed only in your browser.