Ad
Code
Diff
  • def count_prime(n, prime, factors):
        count = 0
        
        while n % prime == 0: 
            count += 1
            n //= prime
    
        if count: 
            factors.append((prime, count))
    
        return n, factors
        
    def prime_factorization(n):
        factors = []
        
        n, factors = count_prime(n, 2, factors)
        
        prime = 3
        while prime * prime <= n:
            n, factors = count_prime(n, prime, factors)
            prime += 2
            
        if n > 1: 
            factors.append((n, 1))
    
        return factors
    • def count_prime(n, prime, factors):
    • count = 0
    • while n % prime == 0:
    • count += 1
    • n //= prime
    • if count:
    • factors.append((prime, count))
    • return n, factors
    • def prime_factorization(n):
    • factors = []
    • cnt = 0
    • while n % 2 == 0: cnt += 1; n //= 2
    • if cnt: factors.append((2, cnt))
    • i = 3
    • while i * i <= n:
    • cnt = 0
    • while n % i == 0: cnt += 1; n //= i
    • if cnt: factors.append((i, cnt))
    • i += 2
    • if n > 1: factors.append((n, 1))
    • n, factors = count_prime(n, 2, factors)
    • prime = 3
    • while prime * prime <= n:
    • n, factors = count_prime(n, prime, factors)
    • prime += 2
    • if n > 1:
    • factors.append((n, 1))
    • return factors

Using regexp makes it simpler

Code
Diff
  • import re
    
    class Disemvowel:
        def __init__(self, s):
            self.s = s
    
        def scalpel(self):
              return re.sub(r'[AEIOU]', '', self.s, flags=re.IGNORECASE)
    • import re
    • class Disemvowel:
    • def __init__(self, s):
    • self.s = s
    • def scalpel(self):
    • return ("".join(x for x in self.s if x.lower() not in "aeiou"))
    • return re.sub(r'[AEIOU]', '', self.s, flags=re.IGNORECASE)