AutomateTheBoringStuff.Ch04.Projects package

Submodules

AutomateTheBoringStuff.Ch04.Projects.P1_commaCode module

Comma code

This program converts a list to a comma separated string.

Write a function, to_string() that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item.

Example

>>> from pythontutorials.books.AutomateTheBoringStuff.Ch04.Projects.P01_comma_code import to_string
>>> spam = ['apples', 'bananas', 'tofu', 'cats']
>>> to_string(spam)
'apples, bananas, tofu, and cats'

But your function should be able to work with any list value passed to it.

AutomateTheBoringStuff.Ch04.Projects.P1_commaCode.main()[source]
AutomateTheBoringStuff.Ch04.Projects.P1_commaCode.to_string(input_list: list) → str[source]

To string

Converts elements in list to comma-separated str.

Parameters:input_list – List to convert into a string.
Returns:String with each element in the list separated by a comma and a space with and inserted before the last element.

AutomateTheBoringStuff.Ch04.Projects.P2_charPicGrid module

Character Picture Grid

This program converts a matrix to an image.

Say you have a list of lists where each value in the inner lists is a one-character string, like this:

grid = [['.', '.', '.', '.', '.', '.'],
        ['.', 'O', 'O', '.', '.', '.'],
        ['O', 'O', 'O', 'O', '.', '.'],
        ['O', 'O', 'O', 'O', 'O', '.'],
        ['.', 'O', 'O', 'O', 'O', 'O'],
        ['O', 'O', 'O', 'O', 'O', '.'],
        ['O', 'O', 'O', 'O', '.', '.'],
        ['.', 'O', 'O', '.', '.', '.'],
        ['.', '.', '.', '.', '.', '.']]

You can think of grid[x][y] as being the character at the x- and y-coordinates of a “picture” drawn with text characters. The (0, 0) origin will be in the upper-left corner, the x-coordinates increase going right, and the y-coordinates increase going down.

Copy the previous grid value, and write a function, matrix_to_pic(), that uses it to print the image:

..OO.OO..
.OOOOOOO.
.OOOOOOO.
..OOOOO..
...OOO...
....O....
AutomateTheBoringStuff.Ch04.Projects.P2_charPicGrid.main()[source]
AutomateTheBoringStuff.Ch04.Projects.P2_charPicGrid.matrix_to_pic(matrix: list) → None[source]

Matrix to picture

Converts a matrix of lists with one-character values into ASCII Art.

Parameters:matrix – List with lists containing one-character elements.
Returns:None. Prints the contents of the lists as ASCII Art

Module contents