0

I am doing a Python exercise where I need to remove all duplicated and sort a sentence into alphabetical order. Here is my code:

def removeDupsAndSort(string):
    newList= []
    string = (list(string))
    for item in string:
        if item not in newList:
            newList.append(item)
    newList.sort()
    print("".join(newList))

removeDupsAndSort("hello world and practice makes perfect and hello world again")

When I run the program however, when it coverts the string into a list at the beginning, it converts it into a list of a bunch of single characters. Is there any way to convert the string into a list of words?

Brandon Kheang
  • 597
  • 1
  • 6
  • 19

0 Answers0