Accessing Nested Lists
Write a program to create a list with the values at the given Indexes.
Sample Input 1
3
1 2
0 3
0 1
Sample Output 1
['hockey','grapes','banana']
SOLUTION CODE FOR THE ABOVE QUESTION
#let us declare a nested list and initialize it
nested_list = [['hockey','grapes','banana', 'orange'], [100, 500,800], "hello", 2.0, 5]
#lets start printing the value in index 3, the forst one which is given
print(nested_list[3])#output should be 2.0
#printing the value at 1 2 i.e [1][2]
print(nested_list[1][2])#output should be 800
#print the all values of index 0
print(nested_list[0])#output should be ['hockey','grapes','banana', 'orange']
#printing the value at 0 3 i.e [0][3]
print(nested_list[0][3])#output should be orange
#printing the value at 0 1 i.e [0][1]
print(nested_list[0][1])#output should be grapes
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment