Skip to content

Instantly share code, notes, and snippets.

@cpdean
Created September 10, 2018 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpdean/d506240df3e7c1ff41132a79ea77c6cf to your computer and use it in GitHub Desktop.
Save cpdean/d506240df3e7c1ff41132a79ea77c6cf to your computer and use it in GitHub Desktop.
Decider
i>>> import random
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'no'
>>> ['do it', 'no', 'no', 'no'][random.randrange(4)]
'do it'
>>> ['no'] * 2
['no', 'no']
>>> (['do it'] + ['no'] * 3)[random.randrange(4)]
'do it'
>>> (['do it'] + ['no'] * 3)[random.randrange(4)]
'no'
>>> (['do it'] + ['no'] * 3)[random.randrange(4)]
'no'
>>> (['do it'] + ['no'] * 3)[random.randrange(4)]
'no'
>>> (['do it'] + ['no'] * 3)[random.randrange(4)]
'do it'
>>> a = lambda: (['do it'] + ['no'] * 3)[random.randrange(4)]
>>> import collections
>>> collections.Counter((a() for i in range(1000)))
Counter({'no': 755, 'do it': 245})
>>> collections.Counter((a() for i in range(1000)))
Counter({'no': 756, 'do it': 244})
>>> collections.Counter((a() for i in range(1000)))
Counter({'no': 758, 'do it': 242})
>>> collections.Counter((a() for i in range(10000)))
Counter({'no': 7477, 'do it': 2523})
>>> collections.Counter((a() for i in range(10000)))
Counter({'no': 7557, 'do it': 2443})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment