Created
February 22, 2020 20:34
-
-
Save mayankdawar/8045b785e8595a6856001a52aa2b2bc7 to your computer and use it in GitHub Desktop.
Write code that uses the string stored in sent and creates an acronym which is assigned to the variable acro. The first two letters of each word should be used, each letter in the acronym should be a capital letter, and each element of the acronym should be separated by a “. ” (dot and space). Words that should not be included in the acronym are…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The'] | |
sent = "The water earth and air are vital" | |
acro = "" | |
lst = sent.split() | |
for i in lst: | |
if i in stopwords: | |
lst.remove(i) | |
for j in lst: | |
acro = acro + j[0] + j[1] | |
if j != lst[-1]: | |
acro += ". " | |
acro = acro.upper() |
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
acro1=""
new_lst=sent.split(" ")
for word in new_lst:
if word not in stopwords:
acro1=acro1+(word[:2].upper()+". ")
acro=acro1[:-2]
acro = ""
dummy = []
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
sent = sent.split()
for item in sent:
if item not in stopwords:
acro = acro + item[:2].upper() + ". "
acro = acro[:-2]
print(acro)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
sentlst = sent.split()
acro = []
for i in sentlst:
if i not in (stopwords):
i = i[0:2]
acro.append(i)
acro = (". ".join(acro).upper())
print(acro)