Ad
Code
Diff
  • def feed_the_primates_v1(animals, food):
        food = set(food)
        banana = "🍌"
        if banana not in food:
            return 'No bananas!'
        return [banana for m in animals if m in {"🐒", "🦍"} and banana in food]
    
    
    def feed_the_primates_v2(animals: list, food: list) -> any:
        return 'No bananas!' if "🍌" not in food else list(
            map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals)))
    
    
    • def feed_the_primates_v1(animals, food):
    • if "🍌" not in food:
    • food = set(food)
    • banana = "🍌"
    • if banana not in food:
    • return 'No bananas!'
    • return [f"🍌" for m in animals if m in ["🐒", "🦍"] and "🍌" in food]
    • return [banana for m in animals if m in {"🐒", "🦍"} and banana in food]
    • def feed_the_primates_v2(animals: list, food: list) -> any:
    • return 'No bananas!' if "🍌" not in food else list(
    • map(lambda a: f"🍌{a}", filter(lambda m: m if m in ["🐒", "🦍"] else None, animals)))