请考虑以下列表:
a = ['Orange and Banana', 'Orange Banana']
b = ['Grapes', 'Orange Banana']
如何获得以下结果:
c = ['Orange and Banana', 'Orange Banana', 'Grapes']
答案 0 :(得分:58)
如果您有超过2个列表,则应使用:
>>> a = ['Orange and Banana', 'Orange Banana']
>>> b = ['Grapes', 'Orange Banana']
>>> c = ['Foobanana', 'Orange and Banana']
>>> list(set().union(a,b,c))
['Orange and Banana', 'Foobanana', 'Orange Banana', 'Grapes']
答案 1 :(得分:9)
>>> list(set(a).union(b))
['Orange and Banana', 'Orange Banana', 'Grapes']
谢谢@abarnert