“Liste 2D dans Python” Réponses codées

Python initialise un tableau 2D

x = [[foo for i in range(10)] for j in range(10)]
# x is now a 10x10 array of 'foo' (which can depend on i and j if you want)
Unusual Unicorn

Comment saisir le tableau 2D en Python

matrix = [input().split() for i in range(no_of_rows)] # if only row is given and the number of coloumn has to be decide by user
matrix= [[input() for j in range(no_of_cols)] for i in range(no_of_rows)] # if both row and coloumn has been taken as input from user
Clean Chamois

Liste 2D dans Python


ar = [[0 for j in range(m)] for i in range(n)]

Dull Dunlin

Créez un tableau 2D en Python

def build_matrix(rows, cols):
    matrix = []

    for r in range(0, rows):
        matrix.append([0 for c in range(0, cols)])

    return matrix

if __name__ == '__main__':
    build_matrix(6, 10)
McBurd

Tableau 2D imprimé Python comme table

for row in A:
    for val in row:
        print '{:4}'.format(val),
    print
just-saved-you-a-stackoverflow-visit

Python Declare 2D Liste

length, breadth = x, y
matrix = [[-1 for j in range(breadth)] for i in range(length)]
# every element is -1
Famous Finch

Réponses similaires à “Liste 2D dans Python”

Questions similaires à “Liste 2D dans Python”

Plus de réponses similaires à “Liste 2D dans Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code