破烂清单的交叉点
我想编写一个从用户输入中获取破烂列表的函数并找到交叉点
def intersection():
intersect_list = []
for i in lst[0]:
for j in lst[1]:
if i == j:
intersect_list.append(i)
return intersect_list
lst = ("enter list:")
I want to write a function that takes a ragged list from user input and find the intersection
def intersection():
intersect_list = []
for i in lst[0]:
for j in lst[1]:
if i == j:
intersect_list.append(i)
return intersect_list
lst = ("enter list:")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来处理任意数量
可以使用
itertools.product
:如果您希望用户能够将列表作为标准的Python文字输入,则可以使用itertools.products.products.products.products.products.products.products.strands .literal_eval
:如果您需要一个函数 输入从用户中输入列表并打印交叉点,则只需写
def> def my_awesome_function():
它。Your function can be written to handle an arbitrary number of sublists by using
itertools.product
:If you want the user to be able to input the list as a standard Python literal, you could use
ast.literal_eval
:If you need a function that inputs the list from the user and prints the intersection, just write
def my_awesome_function():
and put the code inside it.