Creating 2 lists from user input in python 3 -
this question has answer here:
- how split sequence according predicate? 3 answers
i'm writing program needs read string user , create 2 lists of words input. 1 words contain @ least 1 upper-case letter , 1 of words don't contain upper-case letters. use single loop print out words upper-case letters in them, followed words no upper-case letters in them, 1 word per line.
so far i've got this:
"""simple program list words of string.""" s = input("enter string: ") words = s.strip().split() word in words: print(word) words = sorted([i in words if i[0].isupper()]) + sorted([i in words if i[0].islower()])enter code here
problem don't know how split 2 separate lists (with conditions listed each list). appreciated
your requirements strange, first part says want have 2 lists, second part says should use loop print strings without uppercase characters , print others.
if first version correct, check duplicated question, otherwise if want use single loop print words without uppercase letters , others can do:
s = input("enter string: ") lowers = [] word in s.strip().split(): if not word.islower(): print(word) else: lowers.append(word) print('\n'.join(lowers))
Comments
Post a Comment