Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 在Python3中从用户输入创建2个列表_List_Python 3.x - Fatal编程技术网

List 在Python3中从用户输入创建2个列表

List 在Python3中从用户输入创建2个列表,list,python-3.x,List,Python 3.x,我正在编写一个程序,需要从用户那里读取一个字符串,并从输入中创建两个单词列表。其中一个单词至少包含一个大写字母,另一个单词不包含任何大写字母。 使用单个for循环打印出包含大写字母的单词,然后是不包含大写字母的单词,每行一个单词 到目前为止,我得到了这个: """Simple program to list the words of a string.""" s = input("Enter your string: ") words = s.strip().split() for word

我正在编写一个程序,需要从用户那里读取一个字符串,并从输入中创建两个单词列表。其中一个单词至少包含一个大写字母,另一个单词不包含任何大写字母。 使用单个for循环打印出包含大写字母的单词,然后是不包含大写字母的单词,每行一个单词

到目前为止,我得到了这个:

"""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

问题是我不知道如何让它分成两个单独的列表,每个列表都列出了条件。感谢您的帮助

您的要求很奇怪,第一部分说您想要两个列表,第二部分说您应该使用for循环打印不带大写字符的字符串,然后打印其他字符串

如果第一个版本正确,请检查重复的问题,否则,如果要使用单个循环打印不带大写字母的单词,然后打印其他单词,则可以执行以下操作:

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))

谢谢,我的问题实际上是如何表达的,这增加了我的困惑,但你的解决方案可以达到我需要的最终结果,所以我希望它被接受,我可以完成它。再次感谢