dimanche 21 mars 2021

I get TypeError: choice() got an unexpected keyword argument 'k' , when using python random.choice

I want to generate a random string of length n, on a given alphabet.

import random
alphabet = "ACTG"
n= 10
# print(''.join(random.choice(alphabet) for x in range(n)) ) # work fine

print(''.join(random.choice(alphabet, k=n))) # doesn't work

The error:

Traceback (most recent call last):
  File "<input>", line 3, in <module>
TypeError: choice() got an unexpected keyword argument 'k'



Aucun commentaire:

Enregistrer un commentaire