任务是。。。
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.
所以我有我的密码。
items=input("Students: ")
items.sort(lambda x, y: cmp(x.lower(),y.lower()))
print(items)
为什么我得到这个,“attribute Error:'str'对象没有属性'sort'”错误
欢呼声已经响起
罗尼
input()
返回字符串。如果希望items
成为列表,可以执行item.split()
:假设
items
是John Mary Bill
然后您可以:
然后执行
items.sort()
,因为items
将是一个列表对象,而不是字符串。相关问题 更多 >
编程相关推荐