简体   繁体   English

太多值无法解压缩运行时错误python

[英]too many values to unpack runtime error python

I am getting an error that states too many values to unpack(expected 2) Here is my code: 我收到一个错误,指出要解压缩的值太多(预期为2),这是我的代码:

fin = open ('ride.in', 'r')
fout = open ('ride.out', 'w')
output=" "
for line in fin:
    line = line.lower()
    for character in line:
        number = ord(character) - 96
        output = output+str(number)+","
ufo,commet=output.split(",-86,")
ufolist = ufo.split(',')
commetlist= commet.split(',')
ufoproduct=1
commetproduct=1
for item in ufolist.items(): #(Line with error)
    ufoproduct = int(item)*ufoproduct
for item in commetlist.items(): #(This would probably have the same error)
    commetproduct=int(item)*commetproduct
if ufoproduct % 47 == commetproduct % 47:
    fout.write("GO")
    fout.close()
    else:
        fout.write("STAY")
    fout.close()

The ride.in has two lines of text ride.in有两行文字

It would've helped to see an example of ride.in file, so that your error can be recreated. 最好看一个ride.in文件示例,以便可以重新创建您的错误。 There's a problem with ufolist = ufo.split(',') - this gives you a list, which you're trying to treat as a dict . ufolist = ufo.split(',') -这为您提供了一个列表,您试图将其视为dict for item in ufolist.items(): doesn't need the .items() part for item in ufolist.items():不需要.items()部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM