Wikipedia:Reference desk/Archives/Language/2022 March 15

= March 15 =

Alphabetical list
Is there a site (or another free resource) where I could paste a list of a few hundred words and have them ordered alphabetically? It may be more difficult but I'd also like to find a similar way to list them by the number of their letters (such as: cat, dog, bear, bird, horse, giraffe, leopard...). Do you have any idea? Thank you! --79.35.50.40 (talk) 19:26, 15 March 2022 (UTC)
 * Does installing Python count as a resource? This would be trivially easy to do in Python: here's how to sort a list alphabetically in Python. You can actually use that page as a resource (click "Try it Yourself"), if you can put your list in the right format. To sort by length instead, change the code by replacing sort with sort(key=len). If you actually install Python it could open a text file and read it line by line, very easily, which saves you having to format it as a Python list ["I", "mean", "like", "this"].
 * I just tried that site with about 250 words, and it works:
 * You might want the output to be formatted in a more useful way though. (This is fixable.) I also notice that it's sorting capital letters separately from lower case, which might not be the desired behavior: that would take another tweak to fix (change it to say sort(key=str.lower)).
 * For nicer output (a comma separated list): instead of print(thislist), put print(", ".join(thislist)).
 * Card Zero (talk) 20:00, 15 March 2022 (UTC)
 * Do you have a spreadsheet program? With MS Excel and LibreOffice Calc you can paste a list into a column of cells then sort it, then copy it back out again.
 * Added: And they have formulae for counting letters, so you can sort by length as well.--Verbarson talkedits 21:11, 15 March 2022 (UTC)
 * And LibreOffice is of course free. (I can't see anything in the Calc docs about counting letters, but I'm not used to spreadsheets.) Card Zero  (talk) 21:25, 15 March 2022 (UTC)
 * LEN(text) --Verbarson talkedits 23:46, 15 March 2022 (UTC)
 * Oh yes. That works. So the only remaining question (assuming the OP is like me and knows nothing of spreadsheets) is how to populate column B with =LEN(A1), =LEN(A2), etc., automatically, so that it can be used as the sort key. (It's about time I learned this myself.) Card Zero  (talk) 00:13, 16 March 2022 (UTC)
 * If cell B1 holds =LEN(A1), then copying it down the column will automatically create B2 =LEN(A2), B3 =LEN(A3). You can usually copy one cell (B1) into a range (eg B2 - B250) as a single action. --Verbarson talkedits 10:48, 16 March 2022 (UTC)
 * Thanks. In Calc the action is to click the tiny square handle in the bottom-right corner of the cell, and drag down the column. I learned a skill! Hope the OP got something out of this too. Card Zero  (talk) 11:54, 16 March 2022 (UTC)
 * In the days of command-line operating systems, sort commands came standard with the operating system; see sort (Unix) for Unix (there was also a sort command that came with MS-DOS). AnonMoos (talk) 23:00, 15 March 2022 (UTC)
 * I just tried the sort command in a Windows cmd prompt (run->cmd) and it worked. (I did sorttest2.txt to turn the file test.txt into the alphabetized file test2.txt.) Doesn't offer an easy way to sort by length, though. Maybe Powershell can sort strings by length? ... yes, I tested and it can! "Get-Content -Path [path] | Sort-Object Length" is the command, where [path] should be replaced with the path to where the unsorted file (one word per line) resides, e.g. C:\Users\yourname\test.txt. This will print the words, sorted by length, to the screen, where they can be copied by selecting and right-clicking. (To open Powershell, it's right-click start menu, run, then type "Powershell".) Card Zero  (talk) 23:18, 15 March 2022 (UTC)
 * I just tried the sort command in a Windows cmd prompt (run->cmd) and it worked. (I did sorttest2.txt to turn the file test.txt into the alphabetized file test2.txt.) Doesn't offer an easy way to sort by length, though. Maybe Powershell can sort strings by length? ... yes, I tested and it can! "Get-Content -Path [path] | Sort-Object Length" is the command, where [path] should be replaced with the path to where the unsorted file (one word per line) resides, e.g. C:\Users\yourname\test.txt. This will print the words, sorted by length, to the screen, where they can be copied by selecting and right-clicking. (To open Powershell, it's right-click start menu, run, then type "Powershell".) Card Zero  (talk) 23:18, 15 March 2022 (UTC)