In this Python list program, we will create a 3*3 grid with numbers in a list using the Python programming language.
Create a 3×3 grid with numbers in list:
Steps to solve the program
- Create an empty list.
- Use a for loop to iterate over numbers from 0 to 2.
- In each iteration add an empty list to the created empty list.
- Use a nested for loop to iterate over numbers from 4 to 6.
- Add those numbers to the empty that we have created in the previous for loop.
- Print the list to see the output i.e. 3×3 grid with numbers
#Input list
list1 = []
for i in range(3):
list1.append([])
for j in range(4,7):
list1[i].append(j)
#Printing output
print("3X3 grid: ",list1)
Output :
3X3 grid: [[4, 5, 6], [4, 5, 6], [4, 5, 6]]
Related Articles
Python program to zip two lists of lists into a list.
Python program to convert the first and last letter of each item from Upper case and lowercase.
Python to find maximum and minimum values in the given heterogeneous list.
Python program to sort a given list in ascending order according to the sum of its sublist.
Python program to extract the specified sizes of strings from a given list of string values.
Python program to find the difference between consecutive numbers in a given list.