how to place a string in a double array python code example

Example 1: python append to 2d array

temp_list = [[], [], [], []]
temp_list[0].append("a1")
temp_list[1].append("a2")
temp_list[2].append("a3")
temp_list[3].append("a4")

Example 2: how to input 2-d array in 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

Tags:

Java Example