how to write a program to alphabetize words in python 27 usi

how to write a program to alphabetize words in python (2.7) using for loops.
for example: (air, is, i, airport, map).

Solution

PROGRAM CODE:

# alphabetizing the strings in python can be carried out by adding the strings in to a list
# The below program has a list to which some words are added
# Then we use the sorted functionality to sort the words in the list in alphabetical order

mylist = [\"air\", \"is\", \"i\", \"airport\", \"map\"]
sortedlist = []
for x in mylist:
   sortedlist.append(\"\".join(sorted(x)))

# Printing the sorted list

for x in sortedlist:
   print x

OUTPUT:
air
is
i
aioprrt
amp

how to write a program to alphabetize words in python (2.7) using for loops. for example: (air, is, i, airport, map).SolutionPROGRAM CODE: # alphabetizing the s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site