[英]Remove outer list from list of list in python
I have a requirement in which I want to pass a set of lists separated by comma to a function. 我有一个要求,我要将一组用逗号分隔的列表传递给一个函数。
searchTerms = ["a", "c", "d"]
stringList = ['a', 'b', 'c', 'd', 'a']
d = dict()
for j in range(len(searchTerms)):
for i in range(len(stringList)):
if searchTerms[j] == stringList[i]:
d.setdefault(j, []).append(i)
print d.values()
if you run the above code the output will be [[0, 4], [2], [3]]
but i need to pass [0, 4], [2], [3]
to a function. 如果运行上面的代码,输出将是
[[0, 4], [2], [3]]
但是我需要将[0, 4], [2], [3]
传递给函数。 Could anyone tell me how can I remove the outer list from here. 谁能告诉我如何从此处删除外部列表。
In short convert [[0, 4], [2], [3]]
------>
[0, 4], [2], [3]
. 简而言之,转换
[[0, 4], [2], [3]]
------>
[0, 4], [2], [3]
。 Thanks 谢谢
I want to send it to this function: 我想将其发送到此功能:
for element in itertools.product([0, 4], [2], [3]):
sortedList = sorted(list(element))
Like this: 像这样:
*[[0, 4], [2], [3]]
Hope it helps! 希望能帮助到你!
Example: 例:
>>> def f(a, b, c):
... print(a, b, c)
...
>>> f(*[1, 2, 3])
1 2 3
In your case: 在您的情况下:
for element in itertools.product(*d.values()):
sortedList = sorted(list(element))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.