Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Python by waketzheng ( 7 years ago )
# Create a list with 8 rows and 8 columns whoes elements are all 'x'
# Solution 1. use for loop:
grid = []
rows = columns = 8
for i in range(rows):
    row = []
    for j in range(columns):
        row.append('x')
    grid.append(row)

# Solution 2: more pythonic way:
grid = [['x'] * columns for _ in range(rows)]
# ['x'] * 3 == ['x','x','x']

 

Revise this Paste

Children: 99408
Your Name: Code Language: