Search code examples
pythonstringfunctioninputacronym

Write a python script that generates an acronym word from a given sentence


Basically we have to make an acronym word where we have to generate short form from a long form sentence.

I tried to run the code but it was showing error while taking the string from the input.


Solution

  • def acronym(s):
        return ''.join([x[0] for x in s.split(' ')])
    
    #here split(' ') will break all the words into a list.
    #x[0] will take the first letters of all words.
    #finally join will again convert it to a string from a list
    
    print(acronym('The State Department'))
    'TSD'