还,
人= ['保罗','弗朗索瓦','安德鲁','苏','史蒂夫','阿诺德','汤姆','丹尼','尼克','安娜','丹','黛安' , '米歇尔', '杰米', '凯伦']
num_teams = 4
L 应包含 4 个子列表,其中包含 0,1,2,3,0,1,2,3 格式的元素索引
def form teams(people, num_teams):
'''make num_teams teams out of the names in list people by counting off. people in a list of people's name(strs) and num_teams(an int >= 1) is the desired
number of teams. Return a list of lists of names, each sublist representing a team.'''
L= []
# Make an outer list
for i in range(num_teams):
L.append([])
# make an i th number of sublist according to the range
for team in range(num_teams) #in this case 0,1,2,3
for i in range(0, len(people), num_teams) #start from 0 to len(people) which in this case is 15 and by taking 0,1,2,3, steps
if (team + i) < len(people): <---??????
L[team].append(people[team+i]) <---??????
return L
print(L)
[['paul', 'steve', 'nick', 'michelle'],['francois','arnold','anna','jeremy'], ['andrew','tom','dan','karen'],['sue','danny','diane']
有人可以解释我放置的那些吗?关于它,我是否正确理解了概念?