2013-04-20 65 views
0

如何通过组合成一个列表理解来解决以下代码复制?如何在Python列表理解中删除代码重复?

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] 

回答

1
[x for x in range(2,100) if x in mylist and x not in theirList if not name or x%2 ]