Ad
Strings
Sets

Ancestor:

def cake_maker(word: str) -> str:
    ingredients = 'cake'
    cake_mix = set()
    idx = 0
    while idx != len(word):
        if word[idx].lower() in ingredients:
            cake_mix.add(word[idx].lower())
        idx += 1
    if len(cake_mix) == len(ingredients):
        return 'Cake'
    return 'Not enough to make the cake!'
  • if you are only using indexes for access -> use a for loop
  • second time lower is used. use it in one location

so, the loop thing looks like this

for char in word.lower():
    if char in ingredients:
        cake_mix.add(char)

and now should be obvious why we use a list/set "comprehention" instead of starting from an empty set.
Also, I like the idea of using sets for this one.
But that means we can use default set operations to check the subset part:

cake_mix >= ingredients is enough.
Taking everything together we arive at my solution.

Timings:
I wanted to compare set speed to other clean version in the ancestory.
I chose:

def list_maker(word: str) -> str:
    return 'Cake' if 'cake' == ''.join([i for i in 'cake' if i in word.lower()]) else "Not enough to make the cake!"

and

def not_in_maker(word: str) -> str:
    for l in "cake":
        if l not in word.lower():
            return "Not enough to make the cake!"
    return "Cake"

For the success case I used the alphabet repeated 1_000_000 times.
For the failing case I used the alphabet without 'a' repeated 1_000_000 times
(I timed it on my machine obv)

  • Ancestor:
    • success: 6.95 seconds
    • failiour: 6.47 seconds
  • MyVersion (set_maker):
    • success: 0.23 seconds
    • failiour: 0.22 seconds
  • list_maker:
    • success: 0.09 seconds
    • failiour: 0.08 seconds
  • not_in_maker:
    • success: 0.07 seconds
    • failiour: 0.04 seconds

From the rough results we can conclude that what looks simplest in code is also the fastest in this case.

Code
Diff
  • def cake_maker(word: str) -> str:
        ingredients = {"c","a","k","e"}
        cake_mix = set(word.lower())
        if cake_mix >= ingredients:
            return 'Cake'
        else:
            return 'Not enough to make the cake!'
    
    • def cake_maker(word: str) -> str:
    • ingredients = 'cake'
    • cake_mix = set()
    • idx = 0
    • while idx != len(word):
    • if word[idx].lower() in ingredients:
    • cake_mix.add(word[idx].lower())
    • idx += 1
    • if len(cake_mix) == len(ingredients):
    • ingredients = {"c","a","k","e"}
    • cake_mix = set(word.lower())
    • if cake_mix >= ingredients:
    • return 'Cake'
    • return 'Not enough to make the cake!'
    • else:
    • return 'Not enough to make the cake!'
Code
Diff
  • def return_10():
        return int(ord("ᕟ")^ord("ᕕ"))
        
        
        
    • def r():
    • def t():
    • return int("10",2)
    • def e():
    • return int("1000",2)
    • return t() ^ e()
    • return_10 = r
    • def return_10():
    • return int(ord("ᕟ")^ord("ᕕ"))