how to search for a capital letter within a string and return the list of words with and without capital letters

前端 未结 9 1188
无人共我
无人共我 2020-12-18 23:23

My homework assignment is to Write a program that reads a string from the user and creates a list of words from the input.Create two lists, one containing the words that con

9条回答
  •  甜味超标
    2020-12-18 23:39

    I think your answer might only be searching for words where the first letter is capitalized. To find words that contain a capital letter anywhere in the word, you'd have to enumerate over each letter in the word, like this:

    uin = input("Enter your text: ")
    
    ##create lists to hold upper and lower case words
    up_words = []
    no_up_words = []
    
    for i, word in enumerate(uin.strip().split()):
        if word.islower():
            no_up_words.append(word)
        else: 
            up_words.append(word)
    
    print(up_words, no_up_words)
    

提交回复
热议问题