list
), tuples (tuple
), strings (str
) in Python, use choice()
, sample()
, choices()
of the random
module.choice()
returns one random element, and sample()
and choices()
return a list of multiple random elements. sample()
is used for random sampling without replacement, and choices()
is used for random sampling with replacement.- Pick a random element:
random.choice()
- Random sampling without replacement:
random.sample()
- Random sampling with replacement:
random.choices()
- Set a seed
- Related:Shuffle a list, string, tuple in Python (random.shuffle, sample)
Pick a random element: random.choice()
random.choice()
returns one random element from the list.Random sampling without replacement: random.sample()
random.sample()
returns multiple random elements from the list without replacement.1
, a list with one element is returned. If set to 0
, an empty list is returned. if set to the value that exceeds the number of elements of the list, an error raises.tuple()
, join()
.- Related:Convert lists and tuples to each other in Python
- Related:Concatenate strings in Python (+ operator, join, etc.)
Random sampling with replacement: random.choices()
random.choices()
returns multiple random elements from the list with replacement.choices()
was added in Python 3.6 and cannot be used in earlier versions.1 3 Times 1 3
k
. Since elements are chosen with replacement, k
can be larger than the number of elements in the original list.k
is a keyword-only argument, it is necessary to use keywords such as k=3
.k
is set to 1
by default. If omitted, a list with one element is returned.weights
argument. The type of the list element specified in weights
can be either int
or float
. If set to 0
, the element is not selected.cum_weights
. cum_weights
in the following sample code is equivalent to the first weights
in the above code.weights
and cum_weights
both set to None
by default, and each element is selected with the same probability.weights
or cum_weights
is different from the original list, an error raises.weights
and cum_weights
at the same time.Print Selection Pc
Set a seed
random.seed()
, the seed for generating random numbers can be set.There are times when you want to print something from a Web Page, but you want to print ONLY a certain selection, without all the graphics and without all the other text.
If you are using Microsoft Internet Explorer (MSIE), you can choose to print your selection this way: Resume templates 2 0 60.
- Put your mouse cursor just in front of the beginning of the text you wish to print out;
- LEFT-click the mouse AND HOLD DOWN THE BUTTON;
- While holding down the button, drag the cursor to the end of the text you wish to print;
- Release the button;
- The text you chose has now been 'highlighted';
- Then, in the Menu Bar at the top of your screen, click on 'File', then click on 'Print';
- When the dialog opens, click in the little round circle in front of 'Selection';
- Then click 'OK'.
- That will print out ONLY the text you selected.
(NOTE: If you included any graphics in the selection, they will print out also.)
The pages on this website are best viewed at a resolution of 1024x768, or, at the least, 800x600. If you are still using a resolution of 640x480, or smaller, you really need to change your Windows properties so that the resolution is at least 800x600. (Nowadays, it is very rare that anyone writing web pages worries about those who are still using a resolution of 640x480; I try to make these pages viewable at that small resolution, but it doesn't always work out. PLEASE use at least 800x600 if possible!)
To change these properties, minimize everything you are using. (Minimizing everything is easily, and quickly, done by holding down the WinKey [the one on the bottom row of your keyboard, with the Windows logo on it], and pressing the 'D' key).
- Then 'right-click' an empty space on your Desktop;
- Left-click on 'Properties';
- Left-click on the 'Settings' tab;
- In the 'Screen Area' section, move the slider to the right until the text says '800 by 600 pixels' (or whatever new resolution you want);
- Click 'OK'.