How to Sort Words in Alphabetic Order using Python?

PythonServer Side ProgrammingProgramming

Assuming that the a string object contains multiple words separated by one space. The split() method of string class returns a list of words separated by space character. This list object is sorted by invoking sort() method of built-in list class

>>> string='Hello how are you?'
>>> list=string.split()
>>> list
['Hello', 'how', 'are', 'you?']
>>> list.sort()
>>> list
['Hello', 'are', 'how', 'you?']
raja
Published on 25-Feb-2018 19:10:13
Advertisements