我按题目所示初始化列表,可是它说不合法,这是为什么呀?
问题:
我的代码:
first = [('dungeon',7),('winterfell',4),('bran',9),('meelo',6)]
second = [[ 'Angle', '0121701100106',99], [ 'Jack', '0121701100107',86], [ 'Tom', '0121701100109',65], [ 'Smith', '0121701100111', 100], ['Bob', '0121701100115',77], ['Lily', '0121701100117', 59]]
m = input()
n = input()
modified_first = sorted(first, key=lambda first_element:first_element[1])
alpha_second = sorted(second, key=lambda second_element:second_element[0])
amount_second = sorted(second, key=lambda second_element:second_element[2])
first_output = []
if m <= 4:
for i in range(m):
first_output.append(modified_first[i])
print(first_output)
else:
print(modified_first)
second_output1 = []
if n <= 6:
for i in range(n):
second_output1.append(alpha_second[i])
print(second_output1)
else:
print(alpha_second)
second_output2 = []
if n <= 6:
for i in range(n):
second_output2.append(amount_second[i])
print(second_output2)
else:
print(amount_second)
结果: