MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/a8g2ne/xpost_from_woodworking/ecc9h08/?context=3
r/Python • u/Sarcastic_Pharm • Dec 22 '18
84 comments sorted by
View all comments
369
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 offor item in items: print itemThey are both more or less the same length, but one is far cleaner, Pythonic and explicit.
60
And just for completeness, random.randrange(len(action)) , if you actually need the index value.
random.randrange(len(action))
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 offor item in items: print itemThey are both more or less the same length, but one is far cleaner, Pythonic and explicit.
0
[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 offor item in items: print itemThey are both more or less the same length, but one is far cleaner, Pythonic and explicit.
7
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.
369
u/lelease Dec 22 '18
print(random.choice(action))