jeudi 27 décembre 2018

How to select randomly from a list of strings a token excluding numbers?

I know that in python in order to randomly pull a word from a token we could do:

In:

import random 
s = 'hi there 3'
words = s.split() 
random.choice(words)

Out:

3

However, how can I choose the next word (in this case hi) instead of a number? I would like to always guarantee that I am pulling a string not a number?.




Aucun commentaire:

Enregistrer un commentaire