In this Python list program, we will create a sublist of numbers and their squares with the help of the below-given steps.
Create a sublist of numbers:
Steps to solve the program
- Create a list and use the list comprehension method.
- With the help of range, function create a sublist of numbers and their squares.
- Print the list to see the output.
#Input list
list1 = [[i,i**2] for i in range(1,11)]
#Printing output
print(list1)
Output :
[[1, 1], [2, 4], [3, 9], [4, 16], [5, 25],
[6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]
Related Articles
Python program to create a list of five consecutive numbers in the list.
Python program to insert a given string at the beginning of all items in a list.
Python program to iterate over two lists simultaneously and create a list of sublists.
Python program to move all positive numbers on the left side and negative numbers on the right side.
Python program to move all zero digits to the end of a given list of numbers.
Python program to find the list in a list of lists whose sum of elements is the highest.