Lowercase letter diamond
Write a Python program to print the letters a to y in rows of 1, 3, 5, 7, 5, 3, 1 letters.
a b c d e f g h i j k l m n o p q r s t u v w x y
Approach
- Same idea as the previous program with different row sizes.
Solution
import string letters = iter(string.ascii_lowercase)for size in [1, 3, 5, 7, 5, 3, 1]: print(" ".join(next(letters) for _ in range(size)))a b c d e f g h i j k l m n o p q r s t u v w x y
Line by line
An iterator hands out the letters one at a time across all rows.
next(letters) takes the following letter each time it is called.
Learn the concept
New to this topic? Read the lesson, then come back.