mercredi 25 mars 2020

Python choice in an ordered array, picking value one after another

I am trying to do a simple process on python, I know there is an answer out here on how to achieve this, but I can't seem to find it.

Python should make selection from a list of data on a txt file, but in an ordered form. Say it would pick the first value when prompted, then the second value,and so on until the list is exhausted.

Is there a way to achieve this without random? The only way I have seen so far are randomly, and randomly without/with replacement. The order of choice is very important here.

              import random
              with open ("questions.txt","r") as f:
              question = f.readlines()
              post = (random.choice(question).strip())
              print (post)

The code above only do so randomly and not what I want, I want it ordered and stop when the list is finished.




Aucun commentaire:

Enregistrer un commentaire