我试图根据用户的数据创建列表。这个数据是一个16道问题调查,所以我想把数据分成16个答案的列表,或者是一个列表,只是我的代码如下图所示。基于两个条件创建列表
studentanswers = []
contains_data = False
temp = []
for i in answers:
if i == 'No data available':
if contains_data:
studentanswers.append(temp)
temp = []
studentanswers.append([i])
contains_data = False
else:
studentanswers.append([i])
else:
contains_data = True
if len(temp) < 16:
temp.append(i)
else:
studentanswers.append(temp)
temp = []
contains_data = False
但是,当我迭代时,数据得到正确的计数,并且一些数据被分配给错误的用户。例如,对于学生1个问题16将成为问题1学生2
目前还不清楚你问什么。请分享示例输入和预期输出。 – janos