【发布时间】:2013-12-14 08:45:01
【问题描述】:
我想传递整个字典的键,在循环中调用的另外 2 个值因此将被组合并逐行打印。值被传递给另一个函数,但只有整个字典的第一个值被传递。我希望所有值与其他变量一起传递,如下所示。我会怎么做才能让所有值都被传递,而不仅仅是一个。
这是我的代码:
class scoring:
def values(self):
dicts = {}
inner_dict = {}
with open("1.txt","r") as f:
for line, score in zip(sys.stdin, f):
d2 = ast.literal_eval(score)
for key,v in d2.items():
inner_dict = dicts.setdefault(key, {})
inner_dict['s'] = v.get('s')
sent = dicts[key]['s']
binary = re.split("\s+", line.strip())[0]
return key, sent, binary
def score(self,key,sent,binary):
<something>
if __name__ == "__main__":
call = scoring()
key,sent,binary = call.values()
call.score(key,sent,binary)
【问题讨论】:
标签: python file list file-io dictionary