How to create a 2D array and fill it with given 3 different characters in Python

1 Answer

0 votes
chars = ['#', '$', '*']

size = 4 # 4 x 4 

list_2d = [[chars[(i + j) % len(chars)] for j in range(size)] for i in range(size)]

print(list_2d)



'''
run

[['#', '$', '*', '#'], ['$', '*', '#', '$'], ['*', '#', '$', '*'], ['#', '$', '*', '#']]

'''

 



answered Feb 16, 2024 by avibootz
...