Sorting a line-based list and removing duplicates can produce a result you didn't expect โ here's the sorting logic behind it.
String sort vs. numeric sort
Sorting as strings puts "10" before "9", since the character '1' is less than '9'. To get true numeric order (9, then 10), the values need to be recognized as numbers โ a "natural sort."
Case sensitivity
A case-sensitive sort puts "Banana" before "apple", since uppercase letters come before lowercase in ASCII. For the ordering a human expects, use a case-insensitive sort option instead.
A caveat when deduping
"apple" and "Apple " (with a trailing space) are often only recognized as duplicates if they match exactly in both case and whitespace. Trimming whitespace and normalizing case before sorting makes deduplication more accurate.