03 - List, Tuple - Exercise
03 - List, Tuple - Exercise
Hello Innominion,
• Some other topics are required to solve some questions. don't panic.
LIST
Question::Create a list of numbers
nums = [1,2,3,4]
[1, 2, 3, 4]
# Method 1
[1, 2, 4]
# Method 2
[1, 2, 4]
# Method 3
[1, 2, 4]
• lst = [2,3,4]
[1, 2, 3, 4]
['D', 'o', 'n', "'", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']
['D', 'o', 'n', 't', ' ', 'p', 'a', 'n', 'i', 'c']
# CODE HERE
['o', 'n', 't', ' ', 'i', 'c', 'p', 'a', 'n', 'D']
Question: Join the given list ['p', 'a', 'n', 'D', 'a']
# CODE HERE
'panDa'
Tuples
Question: Create a tuples for numbers 31,24,35,85 as nums
# CODE HERE
data type <class 'tuple'>
(31, 24, 35, 85)
# CODE HERE
# CODE HERE
Question: Write code to check whether an element ('i') exists within a tuple.
• tpl = ('i','n''n','0')
# CODE HERE
True
• list = ['Hello',100,[],'innomatics']
# CODE HERE
# CODE HERE
tpl = ("Innomatics")
('s', 'c', 'i', 't', 'a', 'm', 'o', 'n', 'n', 'I')
tpl = (1,2,3)+(4,)
tpl
(1, 2, 3, 4)
Question: Write a Python program to add one more value at last postion of tuples in a list
• tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
• hint- use for loop
# CODE HERE
tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
[(10, 20, 40, 100), (40, 50, 60, 100), (70, 80, 90, 100)]
• tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
• hint- use for loop
# CODE HERE
tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
5 2 4 6 2 2
second higest is : 5
(2, 4, 6, 8, 10)
Descriptive Questions