You are viewing a single comment's thread. Return to all comments →
Use a set to search for vowels, O(1) instead of O(n), n = |vowels| Also single loop instead of two loops i.e. list comprehensions.
def minion_game(string): # your code goes here vowels = set() [vowels.add(x) for x in 'AEIOU'] slen = len(string) volscore = 0 conscore = 0 for i in range(slen): n = slen - i if s[i] in vowels: volscore += n else: conscore += n if conscore > volscore: print(f"Stuart {conscore}") elif conscore < volscore: print(f"Kevin {volscore}") else: print("Draw") if __name__ == '__main__': s = input() minion_game(s
Seems like cookies are disabled on this browser, please enable them to open this website
The Minion Game
You are viewing a single comment's thread. Return to all comments →
Use a set to search for vowels, O(1) instead of O(n), n = |vowels| Also single loop instead of two loops i.e. list comprehensions.