Program: Write a program to print all the words starting with an alphabet “a” and also print the location at which the word is present in the list.
In this program of Python you would be introduced to usage of lists and iterating through them, lists are one of the important topics in python and is widely used for many purposes in writing hug programs.
We had picked up this problem from one of the facebook groups who were looking for a solution 🙂
#below variable maintains the index while we are iterating through a list
index = 0;
#Initialise a list words as below
items=["apple", "aardvark", "parrot", "table", "noise", "annoying", "conversation", "abrupt", "obsolete", "herring", "ant", "helicopter"] ;
#iterate through each word in a list and check for words starting with alphabet "a"
for item in items:
if item == 'a':
print item , " at location:" , index;
index = index + 1; #increment the word count irrespective of whether it starts with "a" or not.
The above code will print the list of all words which start with alphabet “a” along with the location at which it is present in the list of words.
Please do revert to us in form of comments, we would be more than happy to respond.
Founder of TestingTools.co, constantly shares knowledge on different test automation tools. Has experience in building proof of concepts, solutions, frameworks, platforms & implementation of test automation projects.
In pursuit of building a platform with inbuilt framework and reusable components for Oracle Cloud applications ( Oracle HCM, CX, SCM, Financials clouds, Salesforce and other cloud applications )
Major accomplishments in his career:
Product architect and development manager for test automation platforms
Oracle Flow Builder @ Oracle
CloudTestr @ Suneratech
2 times to oracle open world
More than 20 successful POCs ( Proof of concepts )
Designed pricing models.
Trained more than 50 members.
Built more than 100 re-usable functions.
Worked with tools: