Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在遍历列表的列表。。。TypeError:参数类型为';浮动';这是不可容忍的_Python_Loops - Fatal编程技术网

Python 正在遍历列表的列表。。。TypeError:参数类型为';浮动';这是不可容忍的

Python 正在遍历列表的列表。。。TypeError:参数类型为';浮动';这是不可容忍的,python,loops,Python,Loops,我不明白为什么我要返回这个错误 for i in range(len(AmDeliveryPricelist)): if AmDeliveryPricelist[i] == 'nan': continue for j in range(len(AmDeliveryPricelist[i])): AmPricelist[i][j] = re.findall(r'(?:\d+\.)?\d+.\d+', AmPricelist[i

我不明白为什么我要返回这个错误

        for i in range(len(AmDeliveryPricelist)):
        if AmDeliveryPricelist[i] == 'nan': continue
        for j in range(len(AmDeliveryPricelist[i])):
            AmPricelist[i][j] = re.findall(r'(?:\d+\.)?\d+.\d+', AmPricelist[i][j])[0]
            if 'FREE' in AmDeliveryPricelist[i][j]:
                AmDeliveryPricelist[i][j] = 0.
            else:
                AmDeliveryPricelist[i][j] = re.findall(r'(?:\d+\.)?\d+.\d+', AmDeliveryPricelist[i][j])[0]
这就是错误:

Traceback (most recent call last):

  File "<ipython-input-38-3098773b6c36>", line 6, in <module>
    if 'FREE' in AmDeliveryPricelist[i][j]:

TypeError: argument of type 'float' is not iterable
我不明白为什么这段代码会因为这个错误而失败。据我所知,我要求它在范围内迭代,这是可测试的

我在其中添加了一个打印(I,j),在打印(0,0)后代码中断

任何帮助都将不胜感激

既然你问了为什么你的代码不起作用,下面是答案:

在这个if语句中,您试图查看
字符串是否属于
浮点型

if 'FREE' in AmDeliveryPricelist[i][j]:
    AmDeliveryPricelist[i][j] = 0.

我认为这不是你想要的行为,所以你应该考虑解决这个问题!希望有帮助

AmDeliveryPricelist[i][j]
是一个浮点数,您不能在
中对浮点数使用
<0.0中的代码>'FREE'抛出异常。不要在列表中混合使用字符串和浮动(0.0值)。明白了!!谢谢是的,这不太正确,我不得不在价格上加上str()。我设计了它,所以它们都是以字符串的形式出现的,但是有些讨厌的0.0浮动在那里的某个地方。。一定要找到!!谢谢你的帮助
if 'FREE' in AmDeliveryPricelist[i][j]:
    AmDeliveryPricelist[i][j] = 0.