mercredi 10 mars 2021

how read lines file with two columns in random choice function

I have a file, which consists of two columns. I do not know how I can use it in random.choice/sample to randomly choose a word from the first column.

How can I get only the first column if I want to random words only?

random.choice(open(file).readlines())

Is this the correct way?

i     A
am    B
well  C
.
what  W
about Y
you   Z
?
she   M
is    N
dreaming O
.



Aucun commentaire:

Enregistrer un commentaire