Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python Program to Sort Words in Alphabetic Order.py #2050

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Python Program to Sort Words in Alphabetic Order.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Program to sort alphabetically the words form a string provided by the user
# Program to sort words alphabetically and print them out in a list

#declaring variables
my_str = "Hello this Is an Example With cased letters"
word_Dict = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this dictionary is used for no reason at all?

count = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this variable count is used for no reason of it being anywhere in the program.


#Need to make all words the same case, otherwise, the .sort() function sorts them by ASCII code and they will not appear alphabetically.
my_str = my_str.lower()

# To take input from the user
#my_str = input("Enter a string: ")

# breakdown the string into a list of words
words = my_str.split()

# sort the list
words.sort()

# display the sorted words

print("The sorted words are:")
for word in words:
print(word)
print(words)