我正在尝试从列表中删除子列表并获取此错误:ValueError:list.remove(x):x not in list
我希望删除子列表,尽管x只有少数来自子字符串的元素
类似的东西:
list_a=[[1,2,3],[4,5,6]]
list_a.remove([1,3])
list_a
[4,5,6]
Run Code Online (Sandbox Code Playgroud)
来自以下评论:
我有产品清单:
products=[['0001', 'Hummus', 'Food', 'ISR', '10-04-2015'], ['0002', 'Guinness', 'Food', 'IRL', '11-04-2015']]
Run Code Online (Sandbox Code Playgroud)
lst[0],lst[2]并且lst[3]每种产品都是独一无二的.我希望删除整个子列表,通过这三个元素,如:
>>> products.remove(['0001', 'Food', 'ISR'])
>>> products
['0002', 'Guinness', 'Food', 'IRL', '11-04-2015']
Run Code Online (Sandbox Code Playgroud)
.
def del_product(depot, product_data):
'''
del_product
delets a validated product data from the depot
if such a product does not exist in the depot
then no action is taken
arguments:
depot - list of lists
product_data - list
return value: boolean …Run Code Online (Sandbox Code Playgroud) 我想制作包含n个元素的嵌套列表,其中包含给定列表的所有排列.
预期输出如下:
n=3
print perm(n, [1,2])
[[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
Run Code Online (Sandbox Code Playgroud)
我怎么能写一个python代码来做同样的事情.