파이썬 이차원 배열(Python two dimensional arrays)
mlist1 = [
    [7, 12, 23],
    [22, 31, 9],
    [4, 17, 31]]
     
print mlist1 # [[7, 12, 23], [22, 31, 9], [4, 17, 31]]
     
# show list_item at index 1
print mlist1[1] # [22, 31, 9]
     
# show item 2 in that sublist
print mlist1[1][2] # 9
     
# change the value
mlist1[1][2] = 99
     
print mlist1 # [[7, 12, 23], [22, 31, 99], [4, 17, 31]]

파이썬 이차원 배열 생성
    # create a 10 x 10 matrix of zeroes
    matrix10x10 = [[0 for col in range(10)] for row in range(10)]
     
    # fill it with 1 diagonally
    for i in range(10):
    matrix10x10[i][i] = 1
     
    # show it
    for row in matrix10x10:
    print row
     
    """
    [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
    [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
    [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
    [0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
    """

+ Recent posts