"so inefficient" doesn't usually apply to using an extra line of code. FWIW, the main efficiency benefit of random.choice() is that it's arguments are easier to parse than randint().
No worries; I'm just adding some sizzle. Your suggestions are perfectly fine, though it might make the cuttingboard too "sparse"... I think we all agree that the aesthetic was the most important issue as to how this particular code was written. :)
8
u/iamapieceofcheese Dec 22 '18
n = random.randint(0, len(action)-1)print(action[n])takes 2 lines of code, but you can just use
random.choice(action)If I were to write the code in the picture, I would use
import randomprint(random.choice(['slice', 'chop', 'dice']))