List Functions in Python programming | Hands on coding
Python contains the following list functions.
It is used to get the numbers of elements in list.
fruit_list=["Apple","Orange","Mango"]
print ("List elements : ", fruit_list)
#this line will print length of listprint("Length of list is ",len(fruit_list))
"""
***Output***
List elements : ['Apple', 'Orange', 'Mango']
Length of list is 3
"""
It is used to get maximum value from the list.
In case of string focus on ASCII value of first letter of list items.
fruit_list=["Apple","Orange","Mango"]
print("Fruits list :",fruit_list)
print ("Max elements : ", max(fruit_list))
animal_list=["Zebra","Dog","Elephant"]
print("Animal list :",animal_list)
print ("Max elements : ", max(animal_list))
int_list=[45,85,36]
print("int list :",int_list)
print ("Max elements : ", max(int_list))
"""
***Output***
Fruits list : ['Apple', 'Orange', 'Mango']
Max elements : Orange
Animal list : ['Zebra', 'Dog', 'Elephant']
Max elements : Zebra
int list : [45, 85, 36]
Max elements : 85
"""
It is used to get minimum value from the list.
In case of string focus on ASCII value of first letter of list items.
fruit_list=["Apple","Orange","Mango"]
print("Fruits list :",fruit_list)
print ("Min elements : ", min(fruit_list))
animal_list=["Zebra","Dog","Elephant"]
print("Animal list :",animal_list)
print ("Min elements : ", min(animal_list))
int_list=[45,85,36]
print("int list :",int_list)
print ("Min elements : ", min(int_list))
"""
***Output***
Fruits list : ['Apple', 'Orange', 'Mango']
Min elements : Apple
Animal list : ['Zebra', 'Dog', 'Elephant']
Min elements : Dog
int list : [45, 85, 36]
Min elements : 36
"""
It is used to convert sequence types (tuple) into list.
#tuple is created using parentheses
fruit_tuple=("Apple","Orange","Mango")
print("Tuple Items:",fruit_tuple)
#this line convert tuple into list
fruit_list=list(fruit_tuple)
print("List Items :",fruit_list)
"""
***Output***
Tuple Items: ('Apple', 'Orange', 'Mango')
List Items : ['Apple', 'Orange', 'Mango']
"""