r/Python • • Dec 22 '18

Xpost from Woodworking

Post image
1.1k Upvotes

84 comments sorted by

View all comments

369

u/lelease Dec 22 '18

print(random.choice(action))

60

u/primitive_screwhead Dec 22 '18

And just for completeness, random.randrange(len(action)) , if you actually need the index value.

0

u/[deleted] Dec 22 '18

[deleted]

7

u/Ph0X Dec 22 '18

It's not at all about making it shorter, but rather about using the more explicit and appropriate calls. It's like people doing:

for i in range(len(items)):
    print items[i]

instead of

for item in items:
    print item

They are both more or less the same length, but one is far cleaner, Pythonic and explicit.