Dhruv Singhal
May 6, 2023

--

If you want the second element in the temp list to be an integer instead of a string, you can use the int() function to convert the input value to an integer. Here's an updated code snippet that includes the conversion:

my_list=[]

temp_list=[]

n=int(input('Enter the size of list '))

for i in range(n): # for number of sub-list in the list

for j in range(2): # range(2) for size of sub_list

if j == 1:

temp_list.append(int(input()))

else:

temp_list.append(input())

my_list.append(temp_list)

temp_list=[] #set temp_list to null

print(my_list)

This way, when you enter a number for the second element of the sub-list, it will be stored as an integer instead of a string.

--

--

Dhruv Singhal
Dhruv Singhal

Written by Dhruv Singhal

Data engineer with expertise in PySpark, SQL, Flask. Skilled in Databricks, Snowflake, and Datafactory. Published articles. Passionate about tech and games.

No responses yet