I have a list such as
descr_list = ["I","LOVE","DOGS"]
I want a loop that can create sub lists in the order below
["I","LOVE","DOGS"]
["I","LOVE"]
["I"]
["LOVE","DOGS"]
["LOVE"]
["DOGS"]
Here is the loop i currently have and i am getting the below output
for r in range(len(descr_list)):
for j in range(r+1,len(descr_list)+1):
result = descr_list[r:j]
print(result)
['i']
['i', 'love']
['i', 'love', 'dogs']
['love']
['love', 'dogs']
['dogs']
Any help would be greatly appreciated. I know I've done this before but i just can't remember how i did it haha. I need to start at the first element(we can call x) in the list and it needs to read all elements after it. Then walk backwards by 1 element until it gets back to itself and then jump to the next element(x+1) and repeat the same process above until we reach the last element in the list.
question from:
https://stackoverflow.com/questions/65943758/find-combinations-of-list-in-specific-order-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…