Ad
Code
Diff
  • def disemvowel(string):
          return ("".join(char for char in string if char.lower() not in "aeiou"))
    • import time
    • import random
    • import string
    • letters = string.ascii_letters
    • func1 = lambda x: ''.join(y for y in x if y.lower() not in 'aeiou')
    • func2 = lambda x: ''.join(y for y in x if y.lower() not in 'aeiou')
    • for func, name in ((func1, 'filter '), (func2, 'boolean')):
    • start = time.time()
    • for _ in range(80000):
    • word = ''.join(random.choice(letters) for _ in range(70))
    • func(word)
    • print(f'Function with {name} took {round(time.time() - start, 5)} seconds')
    • disemvowel = func2
    • def disemvowel(string):
    • return ("".join(char for char in string if char.lower() not in "aeiou"))