mardi 8 juin 2021

How can two items be randomly selected and moved from one list to another list?

I want a method to select two elements (as sub-lists) from one list and then move them to another list, while removing them from the first list.

My code:

A=[[17, 4, 10, 18, 11], [23, 16, 24, 29, 19, 12, 22], [15, 2, 32, 30, 20, 7, 25], [33, 21, 5, 13, 6, 28, 26, 31], [27, 8, 9, 14, 3]]
B = random.sample(A, 2)
      print("B",B)

My results:

B [[27, 8, 9, 14, 3], [33, 21, 5, 13, 6, 28, 26, 31]]

Expected results:

A [[17, 4, 10, 18, 11], [23, 16, 24, 29, 19, 12, 22], [15, 2, 32, 30, 20, 7, 25]]
B [[27, 8, 9, 14, 3], [33, 21, 5, 13, 6, 28, 26, 31]]



Aucun commentaire:

Enregistrer un commentaire