TOOLTIKI Lovable tool, really free

Why item10 sorts before item2

Sort a list containing item2 and item10 and item10 comes first. Nothing is broken: the comparison runs character by character, "1" is less than "2", and the decision is made at the fifth character before the rest of either string is read.

That single behaviour explains most of what people find surprising about sorted output, and the rest is explained by whitespace you cannot see.

What is natural sort?

The alternative that treats a run of digits as a number rather than as characters. Under natural sort, item2 precedes item10 because 2 is less than 10 — which is what a person means by sorted when the strings contain numbers.

It is not the default anywhere, because it is ambiguous. A version string like 1.10.2 has three numeric runs, a date written 03-04 has two, and treating either as a single value gives the wrong answer. Plain lexicographic sorting is predictable; natural sorting is usually what you wanted.

The workaround that needs no special sorting is zero padding. Rename item2 to item02 and the plain sort agrees with the natural one, which is why log files and exports use padded numbers.

Why do capitals sort first?

Because uppercase letters occupy lower code points than lowercase ones. In the underlying character order every capital comes before every lowercase letter, so "Zebra" sorts before "apple" — the comparison never reaches the second letter.

Sort mode Result
Case-sensitive Apple, Zebra, apple, zebra
Case-insensitive Apple, apple, Zebra, zebra
Natural, case-insensitive Apple, apple, Zebra, zebra

Case-insensitive sorting folds the two together, which is what a reader expects from an alphabetical list. It leaves the relative order of Apple and apple undefined unless the sort is stable, and a stable sort keeps them in the order they arrived.

Accents introduce a third question with no universal answer. Swedish places Å after Z; German files ä alongside a. The same list of names is correctly sorted two different ways depending on the language it belongs to.

Why did deduplication miss a duplicate?

Trailing whitespace, nearly every time. Two lines that look identical differ by a trailing space or a stray tab, so an exact comparison correctly reports them as different.

Line endings are the version of this that catches whole files. Windows ends a line with carriage return plus line feed, Unix with line feed alone. A file written on Windows and split on line feeds leaves a carriage return at the end of every line — invisible, present, and enough to make every entry unique.

That is also why a pasted column from a spreadsheet sometimes refuses to match anything in a lookup. Trim first, then compare; a deduper that trims is doing the useful thing rather than the literal one.

Splitting has the mirror-image problem. A paragraph broken into lines at every full stop is not the same as one broken at every sentence, and a list split on a fixed character count cuts words in half — which is why a splitter that offers to break on a delimiter, a line count or a character count is offering three genuinely different operations.

What breaks when a list becomes one line?

Commas inside the items. Joining "Smith, John" and "Doe, Jane" with a comma produces four fields where there were two, and nothing downstream can tell which commas were separators.

The fix is quoting, and the fix has its own problem: an item containing a quote needs that quote escaped. For a SQL IN list the same applies to apostrophes — an unescaped apostrophe in a name closes the string early, which is the shape of the oldest injection bug there is.

Choose a separator the data cannot contain and the problem disappears. A pipe or a newline is usually safe where a comma is not.

Which operations are reversible?

Numbering, prefixing and joining are — the added text can be stripped again if you know what was added. Sorting is not, because the original order is gone once it is discarded, and shuffling is not for the same reason.

Deduplication is the one that loses most. Removing a duplicate discards the information that the item appeared twice, which is exactly the information a count would have given you.

The practical habit is to keep the original alongside the result until the work is finished. Every one of these tools reads its input and produces new output rather than editing in place, which makes keeping the original a matter of not closing the tab.

Questions people ask

Does sorting handle blank lines? They sort to the top under most comparisons, since an empty string is less than everything. Strip them first if you do not want them.

Can I sort by the second word? Not with a plain line sort. Split the column out, sort, and rejoin — or sort in a spreadsheet, which is built for it.

Is shuffling really random? It uses the browser’s cryptographic random source, so for picking a winner or randomising an order it is sound.

Why does my list lose its last item? A missing final newline. Some tools treat a trailing newline as a terminator and some as a separator, so the count differs by one.

Order it, then join it. The word sorter handles the case and natural questions, shuffle lines does the opposite, number lines and add prefix to lines build the labels, remove duplicate words and remove line breaks clean up, and the list sorter works on whole entries rather than words, and list to comma separated, text to list, the SQL IN list formatter and text to JSON array produce the joined forms with the quoting already handled.