The Minion Game

  • + 0 comments

    I'd call this a cleanup of jpconcerman's solution using list comprehension and a ternary operator for the result. A plain old string will suffice for the vowel list as well but I'm not sure if a list or set ends up being computationally cheaper. For 5 characters though I'd assume the difference is negligible and all three will pass all test cases without timing out.

    def minion_game(string):
        # your code goes here
        vowels = 'AEIOU'
        
        kevin = sum([len(string) - i for i in range(len(string)) if string[i] in vowels])
        stuart = sum([len(string) - i for i in range(len(string)) if string[i] not in vowels])
        
        print('Draw' if kevin == stuart
            else f'Kevin {kevin}' if kevin > stuart
            else f'Stuart {stuart}')