小编Dan*_*iel的帖子

2个列表之间的常见元素比较

def common_elements(list1, list2):
    """
    Return a list containing the elements which are in both list1 and list2

    >>> common_elements([1,2,3,4,5,6], [3,5,7,9])
    [3, 5]
    >>> common_elements(['this','this','n','that'],['this','not','that','that'])
    ['this', 'that']
    """
    for element in list1:
        if element in list2:
            return list(element)
Run Code Online (Sandbox Code Playgroud)

到目前为止,但似乎无法让它工作!

有任何想法吗?

python list

109
推荐指数
9
解决办法
21万
查看次数

标签 统计

list ×1

python ×1