在i列表数量中找到共同值
我希望做上一个问题中描述的事情,而不是列表a,b,c
我有i
列表数(基于用户输入设置):
我如何从此问题中更改代码(如下所示)使用i
列表号码?
>>> a = [1, 2, 3, 4]
>>> b = [2, 3, 4, 5, 6]
>>> c = [3, 4, 5, 6, 10, 12]
>>> elements_in_all = list(set.intersection(*map(set, [a, b, c])))
>>> elements_in_all
[3, 4]
我遇到的问题是我不知道我提前有多少列表!需要以某种方式可以
I wish to do what is described in this previous question but instead of lists a,b,c
I have i
number of lists (that is set based on user input):
Find common values in multiple lists
How can I change the code from this question (shown below) to work with i
number of lists?
>>> a = [1, 2, 3, 4]
>>> b = [2, 3, 4, 5, 6]
>>> c = [3, 4, 5, 6, 10, 12]
>>> elements_in_all = list(set.intersection(*map(set, [a, b, c])))
>>> elements_in_all
[3, 4]
The issue I have is i don't know how many lists I have in advance! needs to be iterable somehow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果从用户那里获得输入,请尝试将其存储在列表中,例如
,使用该变量而不是[a,b,c],在内部映射所有这些列表并将它们转换为设置。
if you get input from the user, try to store it in the list of lists,like
then, use that variable instead of [a, b, c], map internally iterates all these lists and convert them to set.