“2D -Liste in Python” Code-Antworten

Python initialisieren ein 2D -Array

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

So geben Sie 2-D-Array in Python ein

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

2D -Liste in Python


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

Dull Dunlin

Erstellen Sie ein 2D -Array in 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

Python Print 2D -Array als Tabelle

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

Ähnliche Antworten wie “2D -Liste in Python”

Fragen ähnlich wie “2D -Liste in Python”

Weitere verwandte Antworten zu “2D -Liste in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen