我在Python中有两个列表,如下所示:
temp1 = ['One', 'Two', 'Three', 'Four']
temp2 = ['One', 'Two']
Run Code Online (Sandbox Code Playgroud)
我需要创建第三个列表,其中包含第一个列表中不存在于第二个列表中的项目.从我必须得到的例子:
temp3 = ['Three', 'Four']
Run Code Online (Sandbox Code Playgroud)
有没有循环和检查的快速方法?
我为Project Euler 问题35写了一些代码:
#Project Euler: Problem 35
import time
start = time.time()
def sieve_erat(n):
'''creates list of all primes < n'''
x = range(2,n)
b = 0
while x[b] < int(n ** 0.5) + 1:
x = filter(lambda y: y % x[b] != 0 or y == x[b], x)
b += 1
else:
return x
def circularPrimes(n):
'''returns # of circular primes below n'''
count = 0
primes = sieve_erat(n)
b = set(primes)
for prime in primes:
inc = …Run Code Online (Sandbox Code Playgroud)