samedi 2 mai 2020

In simple python, how to generate a zero-list of size n with x ones and y negative ones placed in it randomly?

Something like this,

def T(x, y, n=7):
  # implement this
  pass

For example, T(3, 2) = [1, 0, -1, 1, 1, 0, -1] and T(2, 2) = [1, 0, 1, 0, -1, -1, 0].

I'd like the solution to be just in vanilla python.




Aucun commentaire:

Enregistrer un commentaire