samedi 31 juillet 2021

How to extract some elements randomly from two dimensional list? / Python

I have a 6 x 6 list.

list = [[i for i in range(6)] for j in range(6)]

And I want to extract some elements randomly and then, I wand to change that elements to other character (for example, 'x').

list = [[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 4, 5]]

randomed_list = [[0, 1, x, 3, 4, 5],
[0, 1, 2, 3, 4, 5],
[0, x, 2, 3, 4, 5],
[0, 1, x, 3, 4, 5],
[0, x, x, 3, x, 5],
[0, 1, 2, 3, x, x]]

How can I do? Thanks! :-)




Aucun commentaire:

Enregistrer un commentaire