Day 6
Tuple :
Tuple is an in-built data type in python and is used to collect objects, by separation of commas.
Tuples are mutable.
We use the '( )' operator to denote a tuple
Indexing is the same as the list
Let's solve a few problems on tuples:
- Find the maximum and minimum element in the tuple :
n=(1,5,3,2,0)
print(sorted(n))
print(max(n))
print(min(n))
output:
- To find the sum of the tuple element:
n=(7,9,3,4)
sum=0
for i in n:
sum=sum+i
print(sum)
output:
Problems :
Write a python program to find Row-wise element Addition in Tuple Matrix
Write a python program to update each element in the tuple list
Write a python program to multiply Adjacent elements
Write a python program to join Tuples if the similar initial element
Write a python program to find All pair combinations of 2 tuples
Write a python program to remove Tuples of Length K
Write a python program to remove Tuples from the List having every element as None
Write a python program to sort a list of tuples by the second Item
Write a python program to sort Tuples by Total digits
Write a python program to find Elements frequency in Tuple
Write a python program to filter Range Length Tuples
Write a python program to assign Frequency to Tuples
Write a python program to find Records with Value at the K index
Let's have a look at the basic difference between list
and tuple
:
LIST | TUPLE |
we use '[ ]' operator | we use '( )' operator |
List is mutable | Tuple is immutable |
In my next blog, you will get to about set data types.
Thank you!