I'm trying to insert the number "1" to the list in every position with a for loop and eventually get all possible lists in python.
For Example:
l = ["2","3","6"]
number = "1"
output = [["1","2","3","6"],["2","1","3","6"],["2","3","1","6"],["2","3","6","1"]]
l = ["2","3","6"]
list_of_nrs = []
for index in range(len(l)+1):
l.insert(index, "1")
list_of_nrs.append(l)
del l[index]
print(list_of_nrs)
So I've tried it like the code above me, but the output I get is:
[['2', '3', '6'], ['2', '3', '6'], ['2', '3', '6'], ['2', '3', '6']]
It seems like there is a problem between the append and del function.
source https://stackoverflow.com/questions/69789538/insert-n-in-list-x-append-list-x-to-list-y-delete-n-in-list-x
Comments
Post a Comment