Alphabetize Words

This function is passed a string buffer. It splits the string into words and alphabetizes them. The return value is a list containing the words in alphabetical order.

For the purposes of alphabetizing them, strings are compared with the Python < operator, which compares strings using the built-in ord() function that winds up comparing them based on ASCII values. Thus, upper- and lowercase letters are unequal; the uppercase letters are considered “earlier” than the lowercase ones.

Source Code

						1.     def alphabetize ( buffer ):
 2.
						3.       """Split buffer into words and return a list of them
 4.          in alphabetical order.
 5.
						6.
						7.       """
 8.
						9. ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.