How to decide alphabetical order when space is present? [closed]

for example,

aa

vs

a a

or

PyTorch

vs

Py Discourse


Solution 1:

There are two forms of alphabetical sorting, 'letter by letter' and 'word by word'. In the first you ignore spaces, so Newbury would file before New Zealand. In 'word by word', all phrases beginning with a particular word are filed together, so New Brunswick, New York, New Zealand come before Newbury. However, Py Discourse would file before PyTorch in either method.

Kate (former library cataloguer)

Solution 2:

tchrist claims in a comment to the question that this is a programming question. I disagree. vainaijr asks what order to put strings in, not whether this should be done by programming a computer or by whatever other means.

Space precedes anything else, and so precedes any letter. Thus

Py Z
pyramid
pyramid selling
Pyramiden
python

or

Will, H.
Will, J.
Will, T.
Williams, N.
Williams, R.
Williamson
Wills

Some ignore spaces and punctuation when sorting strings into alphabetical order. That would result in:

Will, H.
Williams, N.
Williamson
Williams, R.
Will, J.
Wills
Will, T.

I would not recommend this, because it misleads the reader. If I were looking in an index for a Williams, and found a block of entries, each entry a Williams, and saw that my Williams was not there, I'd conclude that it was not in the index at all. I wouldn't expect it to be in another block of Williamses, separated from the other block by a Williamson.