text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
ahead and this time do the following | 792.32 | 4.16 |
because i need to shuffle something like | 794.56 | 3.76 |
a deck of cards let me go ahead and not | 796.48 | 3.44 |
just import random but let me give | 798.32 | 3.68 |
myself a variable called cards that's | 799.92 | 4.159 |
going to be of type list and just so i | 802 | 3.839 |
have something to shuffle i don't need | 804.079 | 4.161 |
all 52 cards in a typical deck i'm just | 805.839 | 4.721 |
going to shuffle three cards a jack a | 808.24 | 4.48 |
queen and a king i could call those | 810.56 | 3.519 |
strings anything i want but i just | 812.72 | 3.6 |
wanted a list of some values so as to | 814.079 | 4.081 |
shuffle them up that is randomize the | 816.32 | 3.92 |
order they're in well how does this now | 818.16 | 3.679 |
work if you read the documentation for | 820.24 | 4.08 |
random.shuffle you'll see that it | 821.839 | 5.841 |
shuffles the argument in place that is | 824.32 | 5.04 |
unlike many of the functions we've seen | 827.68 | 4.08 |
it doesn't return to a value that | 829.36 | 4.719 |
contains the shuffled cards in this case | 831.76 | 5.04 |
it actually shuffles the list it's given | 834.079 | 4.88 |
itself so what this means for my code is | 836.8 | 4.08 |
that i need to do something like this | 838.959 | 5.041 |
random random.shuffle and pass in the | 840.88 | 6 |
variable containing those cards and then | 844 | 5.12 |
on a final line here how might i go | 846.88 | 4.88 |
about printing the cards well i could do | 849.12 | 5.12 |
this and i could say print cards but if | 851.76 | 3.84 |
i do that i'm actually going to see | 854.24 | 3.44 |
python syntax for lists and it's just | 855.6 | 4.32 |
going to format in its own way using | 857.68 | 3.76 |
commas and the like i want to print | 859.92 | 3.12 |
these cards out one at a time just | 861.44 | 2.8 |
because i think it'll look a little | 863.04 | 3.28 |
better so we can use some of our syntax | 864.24 | 4.48 |
from loops and say something like this | 866.32 | 5.84 |
for card in cards go ahead and print out | 868.72 | 5.919 |
the current card so what's now happening | 872.16 | 4.96 |
here line three i'm defining a list of | 874.639 | 5.76 |
three cards in this order jack queen | 877.12 | 4.079 |
king | 880.399 | 2.56 |
i'm then shuffling those same cards on | 881.199 | 3.841 |
line four and then on line five i'm | 882.959 | 4.721 |
using a for loop for each of the cards | 885.04 | 5.599 |
in that list print it out one at a time | 887.68 | 5.36 |
and because i'm using print one line at | 890.639 | 4.32 |
a time well let's see the results down | 893.04 | 3.039 |
here in my terminal window i'm going to | 894.959 | 3.761 |
run python of generate.pi and hit enter | 896.079 | 5.44 |
queen king jack seemingly shuffled | 898.72 | 4.559 |
because that's not the order i defined | 901.519 | 3.921 |
earlier let's do it again | 903.279 | 4.321 |
queen king jack | 905.44 | 3.839 |
okay that happens to be the same but | 907.6 | 4.08 |
let's see this could just be bad chance | 909.279 | 5.281 |
there we go jack queen king doesn't look | 911.68 | 4.399 |
like it's shuffled but at least we're | 914.56 | 3.279 |
getting back different orderings now | 916.079 | 2.721 |
again | 917.839 | 3.921 |
jack queen king not so good | 918.8 | 4.88 |
jack queen king not so good this is | 921.76 | 2.879 |
someone you probably want to play | 923.68 | 3.519 |
against with cards queen jack king there | 924.639 | 4.56 |
we go but of course we only have three | 927.199 | 4 |
cards here so there's not that many | 929.199 | 3.601 |
permutations we might see and if we do | 931.199 | 3.601 |
this over time we will see all of them | 932.8 | 4.64 |
but if we had of course 13 or 52 cards | 934.8 | 5.2 |
we'd see a lot more permutations instead | 937.44 | 4.48 |
so we have now these three ways to | 940 | 3.6 |
generate random information one is | 941.92 | 3.68 |
simple coin toss if you want to start | 943.6 | 4 |
some kind of athletic event one pick a | 945.6 | 3.599 |
number between 1 and 10 if you want to | 947.6 | 3.359 |
decide something based on that and now | 949.199 | 4 |
using shuffle we can even take in a list | 950.959 | 4.401 |
of things and shuffle them about so that | 953.199 | 5.121 |
we get some kind of random behavior but | 955.36 | 4.719 |
let me pause here and see if there's any | 958.32 | 2.959 |
questions yet | 960.079 | 4.88 |
on random on modules or any of these | 961.279 | 5.521 |
three functions | 964.959 | 4.32 |
yeah uh can we increase or decrease the | 966.8 | 4.399 |
probability | 969.279 | 3.92 |
of cards | 971.199 | 4.401 |
if you want to uh for example there is | 973.199 | 4.401 |
three there is a 33 percent chance of | 975.6 | 3.28 |
probability | 977.6 | 3.359 |
so is there any chance to increase or | 978.88 | 4.16 |
decrease the probability can you set | 980.959 | 4.401 |
these probabilities not using these same | 983.04 | 4.08 |
functions uh can you set the | 985.36 | 4 |
probabilities but you can absolutely | 987.12 | 3.92 |
implement some of your own functions or | 989.36 | 3.44 |
use more sophisticated functions that do | 991.04 | 3.68 |
exist in this library and others to | 992.8 | 3.92 |
exercise more control these are meant to | 994.72 | 3.6 |
be very user-friendly and simple | 996.72 | 2.96 |
functions certainly the ones we looked | 998.32 | 3.199 |
at that give you equal probability for | 999.68 | 3.76 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.