如何消除python列表理解中的代码重复?
如何通过合并成一个列表来解决以下代码重复问题如何消除python列表理解中的代码重复?,python,list-comprehension,code-duplication,Python,List Comprehension,Code Duplication,如何通过合并成一个列表来解决以下代码重复问题 myList =[ //someList ] thierList=[ //someOtherList ] if name: [x for x in range(2,100) if x%2 and x in mylist and x not in theirList] else: [x for x in range(2,100) if x in mylist an
myList =[ //someList ]
thierList=[ //someOtherList ]
if name:
[x for x in range(2,100) if x%2 and x in mylist and x not in theirList]
else:
[x for x in range(2,100) if x in mylist and x not in theirList]
也可以使用集合
[x for x in range(2,100) if x in mylist and x not in theirList if not name or x%2 ]
set(myList + thierList)