Q:

How to make all possible combinations out of letters, but not all of the letters need to be used?

I'm making a project in Python, and it involves a function that returns all possible combinations out of letters given as a parameter, but not all of the letters have to be used.
This is my current function:
from itertools import product
def algorithm(letters):
    possible = [''.join(combination) for combination in product(letters, repeat=len(letters))]
    return possible
print(algorithm(['a','b','c','d','e']))

But it returns only the combinations that have all the letters given in them. It doesn't return combinations like:
abc
cba
de
ad

etc.
Can anyone help me?

A:

You can do the following:
import itertools

def generate(vals):
    return ("".join(x) for x in itertools.chain.from_iterable(itertools.permutations(vals,i+1) for i in range(0,len(vals))))

print(list(generate("".join(['a','b','c','d','e']))))

This will generate any combination starting from length 1 till 5

