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?']
Updated on 02-Mar-2020 05:15:26