Converting a loop with an assignment into a comprehension

Converting a loop into a comprehension is simple enough: mylist = [] for word in ['Hello', 'world']: mylist.append(word.split('l')[0]) to mylist = [word.split('l')[0] for word in ['Hello', 'world']] But I’m not sure how to proceed when the loop involves assigning a value to a reference. mylist = [] for word in ['Hello', 'world']: split_word = word.split('l') … Read more

Python recursive function error: “maximum recursion depth exceeded”

I solved Problem 10 of Project Euler with the following code, which works through brute force: def isPrime(n): for x in range(2, int(n**0.5)+1): if n % x == 0: return False return True def primeList(n): primes = [] for i in range(2,n): if isPrime(i): primes.append(i) return primes def sumPrimes(primelist): prime_sum = sum(primelist) return prime_sum print … Read more