我努力让我的功能得以发挥作用。以下是它的基础:
#for example:
data=[(b),(c),(d),(e)]
results=[]
for x in data: #this goes through each row of the data
# body_code executes. This part is mostly just changing types, etc
a=final_body_code
results.append(a)
print results
#output should be: results=[(b),(c),(d),(e)] #After changing types of b,c,d,e etc.
#The body of the code does not matter at this point, it's just the appending which i'm
#struggling with.
然而,当我这样做时,它似乎没有附加到结果列表。我是python的新手,所以请帮忙!
答案 0 :(得分:2)
您应该添加示例。
也许您在a=final_body_code
中遇到了一些问题,结果是None
然而,使用list comprehension
对@Mrinal Wahal的回答略有改善results = [final_body_code(i) for i in data]
答案 1 :(得分:0)
我认为这就是你愿意做的事。
data=[(b),(c),(d),(e)]
results=[]
for x in data:
results.append(x)
print results
答案 2 :(得分:-1)
data = [b, c, d, e]
results = []
results.extend(final_body_code(i) for i in data)
return results