类型错误:比较循环的整数和列表
python在这里。 如何解决比较字典循环中的列表和int错误,请提供帮助!
from random import *
passenger = list(range(1,51))
timelist = []
for i in range(1,51):
n = randint(15,51)
timelist.append(n)
passenger_time = {'passenger':passenger, 'timelist':timelist}
for x in passenger_time.values():
if 40 > x > 15:
print('passenger {} accepted'.format(y))
else:
print('not accepted')
Python beginner here.
How can you solve comparing list and int error in for loop of a dictionary, please help!
from random import *
passenger = list(range(1,51))
timelist = []
for i in range(1,51):
n = randint(15,51)
timelist.append(n)
passenger_time = {'passenger':passenger, 'timelist':timelist}
for x in passenger_time.values():
if 40 > x > 15:
print('passenger {} accepted'.format(y))
else:
print('not accepted')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您想要的是:
这在两个列表中并行迭代。它检查一个列表中的值,然后从另一个列表中打印相应的值。
您的代码只是在字典中的两个值迭代。第一次,
x
包含整个pastenger
列表,第二次包含整个timelis
list。做15&lt是没有意义的; x< 40
当x
是列表时。I suspect what you want is:
This iterates over the two lists in parallel. It checks the value in one of the lists, then prints the corresponding value from the other list.
Your code is just iterating over the two values in the dictionary. The first time,
x
contains the entirepassenger
list, the second time it contains the entiretimelis
list. It makes no sense to do15 < x < 40
whenx
is a list.您能否再解释一下您要做的事情(您要比较什么)?
*并写下您的书面:
它可能在python中起作用,就像您写的那样,但是如果您要使用其他语言,您一定会遇到问题
Can you please explain a little more what you're trying to do (what you're trying to compare)?
*and write your if like this:
It might work in python, the way you wrote it, but you're definately going to have a problem if you're gonna use other languages