我如何得到一个列表,每行打印一个单词?

2024-05-14 04:12:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我如何得到一个列表,每行打印一个单词?在

Write a program that takes a list of student names and sorts them to create a class roll. The list of names will be given on a one line separated by a single space.

The program should work like this:

Students: Peng Ivan Alan Jodi Macy
Class Roll
Alan
Ivan
Jodi
Macy
Peng

相反,我的程序是这样工作的:

^{pr2}$

我的程序是:

我如何在每行打印?在


Tags: ofthe程序列表thatnamesprogram单词
3条回答
for item in items:
    print item
    # or print(item) in Python 3

这个程序会给你想要的输出

items=input("Students: ")
items.capitalize()
items = items.split()
items.sort()
print('')
for item in items:
    print(item)

尝试:

print '\n'.join(items)

或者

^{pr2}$

如果不是所有的项目都已经是字符串。在

相关问题 更多 >