Sorry for the puzzling title. For example, I have a list: [a, b, c, d]
I want to generate a ranked list with different combinations in this format:
[a]
[b]
[c]
[d]
[a, b]
[a, c]
[a, d]
[a, b, c]
[a, b, d]
[a, b, c, d]
I'm having trouble in generating this list. So far what I did first was generate each list by adding an element per iteration:
[]
[a]
[a, b]
[a, b, c]
Then I generated the lengths of how the ranked list should look like:
[]
[]
[]
[]
[a]
[a]
[a]
[a, b]
[a, b]
[a, b, c]
Now I'm stuck from here. Is there a library in Python that allows me to do this or can you only do this manually in code? The last thing I have to do is to do a one-to-one list appending from the original list that I generated at the top.
Here's the code of what I have attempted, assume original_list is the original list I made at the top and new_list is the list that I have generated right above this text:
for x in range(0, len(original_list)):
new_list[x].append(original_list[x])
This doesn't work apparently since it appends every item from original_list to the first 4 items in new_list.
EDIT: The elements should be alphabetical with only the last element having different combinations with no repeating element since I'm attempting this on a list with 21 items.