我正在尝试过滤大量看起来像这样的元组:
tuple = ([], [('print', -108.0), ('denim', -144.0), ('floral', -158.0), ('summer', -172.0), ('chiffon', -217.0), ('crochet', -272.0), ('cotton', -275.0), ('graphic', -279.0), ('pattern', -281.0), ('sheer', -294.0)])
我试图做的是创建一些代码行,我可以使用这些代码对Python说,我想要检索一个列表,其中只包含数字大于-200的字符串,在本例中,我希望获得:
list = ["print", "denim", "floral", "summer"]
新部分:
现在多亏了@Andrej Kesely,我找到了这个问题的解决方案,但是如果我想做同样的事情,但是要使用像这样的元组列表:
predictions = [([],
[('print', -72.0),
('summer', -141.0),
('chiffon', -157.0),
('floral', -266.0),
('graphic', -279.0),
('cotton', -279.0),
('denim', -282.0),
('cute', -321.0),
('striped', -331.0),
('pattern', -337.0)]),
([],
[('chiffon', -89.0),
('summer', -214.0),
('pleated', -250.0),
('sheer', -280.0),
('woven', -286.0),
('crochet', -293.0),
('solid', -295.0),
('cotton', -300.0),
('mesh', -316.0),
('party', -332.0)]),
([],
[('crochet', -188.0),
('chiffon', -204.0),
('summer', -209.0),
('floral', -209.0),
('pattern', -214.0),
('print', -233.0),
('cotton', -252.0),
('sheer', -282.0),
('elegant', -294.0),
('striped', -300.0)]),
(['striped'],
[('striped', 73.0),
('summer', -216.0),
('cotton', -252.0),
('chiffon', -287.0),
('denim', -299.0),
('print', -336.0),
('cute', -357.0),
('linen', -365.0),
('sheer', -372.0),
('chic', -385.0)]),
([],
[('summer', -146.0),
('crochet', -227.0),
('party', -233.0),
('cute', -251.0),
('mesh', -281.0),
('chiffon', -289.0),
('solid', -294.0),
('cotton', -301.0),
('floral', -322.0),
('beach', -323.0)]),
([],
[('cotton', -168.0),
('summer', -197.0),
('print', -211.0),
('striped', -227.0),
('graphic', -248.0),
('denim', -260.0),
('pattern', -302.0),
('floral', -336.0),
('solid', -341.0),
('cute', -341.0)]),
([],
[('print', -165.0),
('denim', -216.0),
('cotton', -260.0),
('striped', -262.0),
('graphic', -301.0),
('leather', -327.0),
('mesh', -339.0),
('stretch', -341.0),
('pattern', -346.0),
('summer', -347.0)]),
([],
[('crochet', -124.0),
('chiffon', -165.0),
('floral', -169.0),
('summer', -170.0),
('sheer', -227.0),
('party', -245.0),
('cute', -260.0),
('mesh', -286.0),
('elegant', -302.0),
('print', -308.0)])]
如何创建一个列表列表,其中包含每个元组的列表,其中仅显示数字大于-200的字符串?问题来自图像识别模型的输出,我试图通过以下方式将@Andrej Kesely的代码嵌入到模型输出的for循环中:
predictions=[]
for x in df_images["Media"]:
p= predict(x, labels, model)
prediction = [i for lst in p for i, v in lst if v > -200]
predictions.append(prediction)
但它给了我一个错误:“太多的值无法解包(预期为2)”
您可以使用列表理解:
印刷品:
编辑:使用问题中的新列表
predictions
:印刷品:
相关问题 更多 >
编程相关推荐