mercredi 20 juillet 2016

Python random list generation

I'm looking at a little challenge which requires me to

1.create a function which generates a random lists of size 2 (a list in which it's two elements are randomly generated letters).

2.create a function which scores how well a randomly generated list compares to another pre-defined list, so typically we can think of how many matches we have in each position.

3.create a function which keeps calling and scoring a new randomly generated list until we reach a score of a certain size. It also wants to print the best score for every 1000 generated lists.

I've done 1. and 2. for 3. i've created a function which repeatedly calls the score function until we meet a score of a certain size however i'm unsure how to print the best score per every 1000 generated lists this is because i've used a while loop for this to keep generating until a score of certain size is reached. One solution i had was to store the scores in a list by appending each score starting from an empty list. Then use the max function to print the best scores as the list is sliced into chunks of size 1000.

Is there a better way?




Aucun commentaire:

Enregistrer un commentaire