Acronym generator from long words
In this tutorial, you will learn how to write acronym generator using python.
What is an acronym ?
An acronym is a word formed from the initial letter or letters of each of the successive parts or major parts of a compound term.
Step 1:
First, we will define the acronym generator function which will take a string argument.
def acronym_generator(s):
Step 2:
Then, we make a list containing the string words.
s_list = s.split()
Step 3:
Finally, we should implement a for loop to iterate on the list to concatenate the first character of each word to the acronym string.
acr = "" #initialising the acronym
for i in s_list:
acr += i[0]
then, we return acr
return acr
Let's apply this code !
acronym_generator("North Atlantic Treaty Organization")
'NATO'
another one
acronym_generator("as soon as possible")
'asap'
Commentaires