mercredi 14 septembre 2022

Concat items from two list randomly, in random order, without replacement in Python 3

I tried to make two lists that randomly concat to each other, which created a new list of unique series. What I did so far:

import random
import itertools

letter_list = ['ABCD','EFGH','IJKL','MNOP'] #List of series of letters

number_list = random.sample(range(1000, 9999), 4) #create a list of four 4-digits numbers. 

new_list = list(itertools.product(letter_list,number_list))

print(new_list)

Output I have so far:

('ABCD', 1568) ('EFGH', 9173) ('IJKL', 8897) ('MNOP', 7379)

Output that I want:

[EFGH8897,IJKL9173,ABCD7379,MNOP1568]

A random concat from the letter list and number list, randomly chosen and without replacement. the new list in random order as well.




Aucun commentaire:

Enregistrer un commentaire