Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created February 22, 2020 20:34
Show Gist options
  • Save mayankdawar/8045b785e8595a6856001a52aa2b2bc7 to your computer and use it in GitHub Desktop.
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…
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()
@wazwaz1981
Copy link

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)

@Aliricoder
Copy link

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]

@Ridolarax
Copy link

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