Sample Two Random Prepositions
00:00 In the previous lesson, I showed you a way that you can explore a module a little bit and maybe find some functions that you could use for your code and just keep learning a bit and working with the wide variety of options that code gives you usually to solve a task.
00:15
Now we want to employ this random sample to get two prepositions out of the prepositions list that we have. prepositions
is in my words
tuple at the index 0, 1, 2, 3.
00:30
So words[3]
is how I’ll get access to that list, and then I can just say random.sample()
passing words
at index three.
00:47
And I also need to specify that I want to get two examples out of there. So k=2
, and then I will assign that output to a list that I’ll call prepositions
.
01:02 Okay. Let’s print those prepositions and see whether it’s doing what we expect it to.
01:11 Going to save and run. And I get two prepositions, so that’s looking good now. And I run it again. I get two different prepositions. And again, fortunately, these are always randomly selected and they are unique elements.
01:27 It’s not going to select the same element twice. So yeah, that’s yet another way of solving this, and that was getting two prepositions.
01:40 Cool. Well, we only have one adverb left to pick. Let’s do that in the next lesson.
Become a Member to join the conversation.