Trying to append two lists and shuffle elements of both lists simultaneously with one enumerate function
I am using two functions: 1) appending list_b to list_a 2)shuffling list_a and giving using enumerate function to do indexing.
In addition, I also want to shuffle elements of list_b within the new shuffled list_a and use same enumerate function to index items of both lists in a same number sequence. Below is where I stand so far. Thanks for help
list_a = ["alpha","beta","romeo","nano","charlie"]
list_b = [1,2,3,4,5,6,7]
from random import shuffle
list_a.append(list_b)
shuffle(list_a)
print(list_a)
for idx, val in enumerate(list_a, start=1):
print(idx, val)
Output
['nano', 'charlie', 'alpha', 'beta', [1, 2, 3, 4, 5, 6, 7], 'romeo']
1 nano
2 charlie
3 alpha
4 beta
5 [1, 2, 3, 4, 5, 6, 7]
6 romeo
Aucun commentaire:
Enregistrer un commentaire