Create tuples with random values

Asked

Viewed 897 times

0

Is it possible to create a tuple with random size and values? If so, how?

ex: Run -->(0, 4 , 5) Run --> (2, 1, 7, 9) Run --> (7)... If it was a list I’d use the code:

from random import randint

list = [randint(i + 1, 9) for i in range(randint(1, 5))]

print(lis)

But by transforming the variable into tuple with the same code:

from random import randint

tup = (randint(i + 1, 9) for i in range(randint(1, 5)))

print(tup) 

I receive only the message: Generator Object genexpr at 0x00000186F02FEB10>

1 answer

0


  • A function that’s just a little mention in the python documentation, some hint where you could find more information?

  • I don’t know anything reliable but the documentation, but she has no secret.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.