vendredi 26 juillet 2019

Insert/replace variables from one list into another list

list_x = ["a", "y", "l", "d", "e", "l", "g", "o", "i"]
list_y = ["e", "p", "z"]

I am trying to replace random items from list_x with the items from list_y without adding any duplicates. I've looked into I've looked into random.replace() and random.choice() but I can't seem to figure it out. Example of how the output I am trying to get: new_list_x = ["p", "y", "l", "d", "e", "z", "g", "o", "i"]. The goal is to insert/replace any letters from list_y that are missing in list_x with out exceeding the original number of letters in list_x.




Aucun commentaire:

Enregistrer un commentaire