“Daftar 2D dalam Python” Kode Jawaban

Python menginisialisasi array 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

cara memasukkan array 2-d dalam 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

Daftar 2D dalam Python


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

Dull Dunlin

Buat array 2D di 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 Sebagai Tabel

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

Python mendeklarasikan daftar 2D

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

Jawaban yang mirip dengan “Daftar 2D dalam Python”

Pertanyaan yang mirip dengan “Daftar 2D dalam Python”

Lebih banyak jawaban terkait untuk “Daftar 2D dalam Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya