The inventor of the typewriter — Christopher Scholes1 — put the letters on his first model in alphabetical order. Because the symbols that are often used stood next to each other, the mechanical letter staves of the typewriter often bumped against each other and got stuck. In order to prevent this, Scholes reorganized the symbols of the keyboard. The first Scholes and Glidden typewriter2 that was eventually taken into production around 1873 at the company Remington already had a precursor of the current QWERTY-division. According to a popular myth, Remington placed the letters on the first row of the typewriter so that the sellers could make an impression on the customers by typing the product name TYPEWRITER using the symbols on the first row of the keyboard. It is also often said that TYPEWRITER is the longest word that can be typed with the letters of one single row of the keyboard. Remainders of the original alphabetical division of the keyboard can be found in the sequence DFGHJKL in the middle row of a keyboard.

QWERTY-toetsenbord
QWERTY- keyboard division from a patent of Christopher Sholes (U.S. Patent No. 207,559 from 1878). Some keys are clearly the same as the modern QWERTY division: the C and the X changed places and the M is now next to the N.

Apart from QWERTY other divisions were developed, such as the AZERTY keyboards that are used in France and in Belgium, QWERTZ keyboards that are used in German-speaking and some Eastern-European countries, or the Dvorak keyboard, that was invented by August Dvorak because it is supposed to be better from an ergonomic point of view.

Assignment

  1. Write a function rowKey which can be used to determine on which row of the keyboard a given symbol can be found This symbol must be given to the function as an argument. The function must use the standard division of a QWERTY keyboard, but through an optional argument keyboard, another division can be given to the function. A keyboard division is described by a string where the symbols of the keyboard are listed from left to right and from top to bottom. Between two rows of a keyboard a vertical line ( | ) is placed in the string. The division of a QWERTY keyboard, for example, is given as QWERTYUIOP|ASDFGHJKL|ZXCVBNM and the division of an AZERTY keyboard as AZERTYUIOP|QSDFGHJKLM|WXCVBN. The first row is indicated with row number 1, and the function must print the value None if the given symbol isn't found on the keyboard. When searching, no distinction may be made between uppercase and lowercase letters.

  2. Use the function rowKey to write a function rowWord with two parameters: an obligatory parameter word to which a given word must be given as an argument, and an optional parameter keyboard with the same meaning as in the function rowKey. If the given word can be typed entirely with the letters of one single row of the keyboard, the function must print the number of that row (rows are again numbered from 1) as a result. Otherwise, the function should print the value None. Even if the word is an empty string, the value None must be printed. The function cannot make a distinction between uppercase and lowercase letters.

  3. Use the function rowWord to write a function longestWord. To this function, a list of words must be given as an obligatory argument. From this word list, the function should print the longest word that can be typed using one row of the keyboard. If multiple words have an equal length, the function must print the first word that occurs in the word list. Next to a list of words, two optional parameters can be given to the function: an optional parameter keyboard with the same meaning as for the function rowKey, and an optional parameter row that specifically indicates the letters of which row of the keyboard the words can be formed with. If this last parameter isn't given, it doesn't matter which row the keyboard uses to write the words, as long as the words can be formed with the letters of one single keyboard row.

Epilogue

IBM's ThinkPad 701c's unique butterfly keyboard3 rocked the laptop world when it debuted in 1995. This video shows it in action.

Example

>>> rowKey('U')
1
>>> rowKey('A')
2
>>> rowKey('z')
3
>>> rowKey('?')

>>> azerty = 'AZERTYUIOP|QSDFGHJKLM|WXCVBN'
>>> rowKey('A', keyboard=azerty)
1

>>> rowWord('Tiruppur')
1
>>> rowWord('Jalajala')
2
>>> rowWord('Bavikove')

>>> azerty = 'AZERTYUIOP|QSDFGHJKLM|WXCVBN'
>>> rowWord('Erattupetta', keyboard=azerty)
1
>>> rowWord('Bavikove', keyboard=azerty)

>>> hcesar = 'HCESAROPZ|QTDINULMX|YJBFVGKW'
>>> rowWord('Hazorasp', keyboard=hcesar)
1
>>> rowWord('Xiulin', keyboard=hcesar)
2
>>> rowWord('Bvkv', keyboard=hcesar)
3

>>> cities = ['Alaghsas', 'Erattupetta', 'Hazorasp', 'Piripiri', 'Tuntum']

>>> longestWord(cities)
'Alaghsas'

>>> longestWord(cities, row=1)
'Piripiri'
>>> longestWord(cities, row=2)
'Alaghsas'
>>> longestWord(cities, row=3)

>>> azerty = 'AZERTYUIOP|QSDFGHJKLM|WXCVBN'
>>> longestWord(cities, keyboard=azerty)
'Erattupetta'
>>> longestWord(cities, keyboard=azerty, row=1)
'Erattupetta'
>>> longestWord(cities, row=2, toetsenbord=azerty)
>>> longestWord(cities, keyboard=azerty, row=3)

>>> hcesar = 'HCESAROPZ|QTDINULMX|YJBFVGKW'
>>> longestWord(cities, keyboard=hcesar)
'Hazorasp'
>>> longestWord(cities, keyboard=hcesar, row=1)
'Hazorasp'
>>> longestWord(cities, row=2, keyboard=hcesar)
'Tuntum'
>>> longestWord(cities, keyboard=hcesar, row=3)