0

I'm writing a program that needs to read a string from the user and create 2 lists of words from the input. One with the words that contain at least one upper-case letter and one of the words that don't contain any upper-case letters. Use a single for loop to print out the words with upper-case letters in them, followed by the words with no upper-case letters in them, one word per line.

So far I've got this:

"""Simple program to list the words of a string."""

s = input("Enter your string: ")
words = s.strip().split()
for word in words:
    print(word)
words = sorted([i for i in words if i[0].isupper()]) + sorted([i for i in words if i[0].islower()])enter code here

problem is I don't know how to get it to split into 2 separate lists (with the conditions listed for each list). Any help is appreciated

chasing_cheerios
  • 15
  • 1
  • 1
  • 3

1 Answers1

0

Your requirements are strange, the first part says you want to have two lists, the second part says that you should use the for loop to print the strings without uppercase characters and then print the others.

If the first version is correct, check the duplicated question, otherwise if you want to use a single loop to print the words without uppercase letters and then the others you can do:

s = input("Enter your string: ")
lowers = []

for word in s.strip().split():
    if not word.islower():
        print(word)
    else:
        lowers.append(word)

print('\n'.join(lowers))
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
  • Thanks, my question is actually phrased how it was put to me which added to my confusion but you're solution works to the end result I need so I hope it is accepted and I can be done with it. Thanks again – chasing_cheerios Aug 18 '14 at 16:40