In the ISBN-13 (International Standard Book Numbering) system, each book is assigned a unique 13-digit code. The first twelve digits identify the book itself, whereas the last digit merely serves as a check digit to detect invalid ISBN-13 codes.

ISBN
ISBN in text and barcode.

If $$x_1, \ldots, x_{12}$$ represent the first twelve digits of an ISBN-13 code, the check digit $$x_{13}$$ is computed as \[\begin{align} o &= x_1 + x_3 + x_5 + x_7 + x_9 + x_{11} \\ e &= x_2 + x_4 + x_6 + x_8 + x_{10} + x_{12} \\ x_{13} &= (10 - (o + 3e)\!\!\!\!\mod{10})\!\!\!\!\!\mod{10}\end{align}\] As a result, $$x_{13}$$ always takes a value in between 0 and 9, so that ISBN-13 codes only contain digits.

An ISBN-13 code is at the same time also an EAN-13 barcode. The EAN-13 barcode (originally European Article Number but now renamed into International Article Number even though the abbreviation EAN has been retained) is a 13-digit barcoding standard which is used worldwide for marking products often sold at a retail point of sale. When an EAN-13 barcode encodes a conversion of an ISBN-13 code, its prefix will be either 978 or 979 and those are the only valid prefixes for ISBN-13 codes. The fourth digit identifies the country where the book was published. Countries using the same language are grouped into the same category. The following table gives an overview of these categories.

group identifier registration group
0, 1 English speaking countries
2 French speaking countries
3 German speaking countries
4 Japan
5 Russian speaking countries
7 China
6, 8, 9 Other countries

Assignment

Write a function overview that takes a list (list) of strings (str) representing ISBN-13 codes. The function must print an overview that shows the distribution of the list of ISBN-13 codes over the different registration groups. Invalid ISBN-13 codes must be included in the overview under the category Errors. Use the names of the registration groups and maintain their order as given in the example below. Registrations groups for which no ISBN-13 codes occur in the list should also be included in the overview (having 0 occurrences).

Example

>>> codes = [
...    '9789743159664', '9785301556616', '9797668174969', '9781787559554',
...    '9780817481461', '9785130738708', '9798810365062', '9795345206033', 
...    '9792361848797', '9785197570819', '9786922535370', '9791978044523', 
...    '9796357284378', '9792982208529', '9793509549576', '9787954527409', 
...    '9797566046955', '9785239955499', '9787769276051', '9789910855708', 
...    '9783807934891', '9788337967876', '9786509441823', '9795400240705', 
...    '9787509152157', '9791478081103', '9780488170969', '9795755809220', 
...    '9793546666847', '9792322242176', '9782582638543', '9795919445653', 
...    '9796783939729', '9782384928398', '9787590220100', '9797422143460', 
...    '9798853923096', '9784177414990', '9799562126426', '9794732912038', 
...    '9787184435972', '9794455619207', '9794270312172', '9783811648340', 
...    '9799376073039', '9798552650309', '9798485624965', '9780734764010', 
...    '9783635963865', '9783246924279', '9797449285853', '9781631746260', 
...    '9791853742292', '9781796458336', '9791260591924', '9789367398012' 
... ]
>>> overview(codes)
English speaking countries: 8
French speaking countries: 4
German speaking countries: 6
Japan: 3
Russian speaking countries: 7
China: 8
Other countries: 11
Errors: 9

Ask Pythia …

In the following instruction video, Pythia explains how to tackle this assignment. Watch this video as a stepping stone to solve other exercises about sets and dictionaries1.