I recently started playing with Python. What can I do better?
def sieve_of_sundaram(limit):
new_limit = (limit - 1) // 2
boolean_list = [True] * new_limit;
i = 1
j = i
while (i + j + 2 * i * j <= new_limit):
while (i + j + 2 * i * j <= new_limit):
boolean_list[2 * i * j + i + j - 1] = False
j += 1
i += 1
j = i
primes = [2]
for i in range(0, new_limit):
if boolean_list[i]:
primes.append(i * 2 + 3)
return primes
def sieve_of_eratosthenes(limit):
boolean_list = [True] * limit;
for i in range(2, limit):
if i * i > limit:
break
while boolean_list[i - 1] == False:
i += 1
for j in range(i * i, limit + 1, i):
boolean_list[j - 1] = False
primes = []
for i in range(1, limit):
if boolean_list[i] == True:
primes.append(i + 1)
return primes
i = 100
sundaram_primes = sieve_of_sundaram(i)
eratosthenes_primes = sieve_of_eratosthenes(i)
print("Sundaram primes count: ", len(sundaram_primes))
print(sundaram_primes)
print("Eratosthenes primes count: ", len(eratosthenes_primes))
print(eratosthenes_primes)