Basics of  Python-6

Basics of Python-6

Day 6

Tuple :

Tuple is an in-built data type in python and is used to collect objects, by separation of commas.

  1. Tuples are mutable.

  2. We use the '( )' operator to denote a tuple

  3. Indexing is the same as the list

Let's solve a few problems on tuples:

  1. 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:

  1. 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 :

  1. Write a python program to find Row-wise element Addition in Tuple Matrix

  2. Write a python program to update each element in the tuple list

  3. Write a python program to multiply Adjacent elements

  4. Write a python program to join Tuples if the similar initial element

  5. Write a python program to find All pair combinations of 2 tuples

  6. Write a python program to remove Tuples of Length K

  7. Write a python program to remove Tuples from the List having every element as None

  8. Write a python program to sort a list of tuples by the second Item

  9. Write a python program to sort Tuples by Total digits

  10. Write a python program to find Elements frequency in Tuple

  11. Write a python program to filter Range Length Tuples

  12. Write a python program to assign Frequency to Tuples

  13. 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 :

LISTTUPLE
we use '[ ]' operatorwe use '( )' operator
List is mutableTuple is immutable

In my next blog, you will get to about set data types.

Thank you!