Shuffling a List
Random Sampling from a List
Flipping a Coin
Magic 8 Ball
Here is a list with its replies.
replies = ["As I see it, yes.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "It is certain.", "It is decidedly so."]
Generating Pseudorandom Integers
Roll a pair of dice. Roll an exotic die from an RPG, say 20-sided
Generating Uniform Variates
- strings This iterator walks through a string one character at a time in index order.
- lists and tuples Their iterators walk through one element at a time in index order.
- sets The iterator walks through the set in no particular order.
- dictionaries The iterator walks the keys of a dictionary one key at a time in no particular order.
- file objects The iterator walks through a file one line at a time.
Here are some other iterables.
- range objects
- dictionary_keys object
- dictionary_values object
We will do tons of examples.
enumerate
and reversed
are very handy
for altering the behavior of iterators.