python - Generating a certain amount random words from an external file -


This is probably really easy but no solution can be found. I have a text file that contains 10 5-characters There are words, what I want to do is randomly choose 9 out of 9 words and print them.

Currently I have found:

  import random randomword = [line.strip () for open in line ('10 .txt ')] Print ( Random choice (random word))  

This generates a random word from the list of 10 - but I want to generate it in 9 out of 10 without any repetition . Can anyone give me a simple solution?

You use a certain number of specific elements to populate a population:

  random.sample (randomword, 9)  

You probably do not read the entire file, but I continue to think that this is a different one.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -