0

如何通过组合成一个列表理解来解决以下代码重复?

 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] 
4

2 回答 2

1
[x for x in range(2,100) if x in mylist and x not in theirList if not name or x%2 ]
于 2013-04-20T14:29:09.913 回答
0

或者您可以使用集合http://docs.python.org/2/library/sets.html

set(myList + thierList)
于 2013-04-25T08:32:41.430 回答