Python Tutorial 3-Index Function in Python

Index Function in Python

Index function helps to find the position of specific string in a sentence. In many cases in data, instead of getting complete text value, user want to find and extract specific text from a sentence. In below examples, user want to find the City and Pin code by reading number plate of cars. There are three python objects which have been created to complete this task.

#list of number plates of cars

car1 = ['DL-2C-3321','MH-02-8832','HR-05-4332']
#dictionary showing the pin code based on last 4 digit of car plates

car2 = {
'3321': 110018,
'8832' : 400021,
'4332' : 122009,
}
#dictionary showing city name based on first two strings of number plates.

car3 = {
'DL' : 'delhi',
'MH' : 'Maharastra',
'HR' : 'Haryana'
}
# Functions and steps to extract the city and pin code from number plates.

carindex=car1.index('DL-2C-3321')
carindex
city=car1[carindex][0:2]
pin=car1[carindex][6:11]
car3[city]
car2[pin]

Hope above example will help reader to understand the usage of index and other methods in python. Readers are requested to keep watching our blogs to free tutorials for python . We also provide full time Data Science Training in Delhi, Python Training in Delhi, Machine learning in Delhi . We are best Data Science Training Institute in Delhi and have best Data Scientist to provide classroom training in Delhi. Please write to us if you are looking for classroom training for Data Science in Delhi.

LEAVE A COMMENT

Code Calibre