Q:

Write a Python program to get all possible combinations of the elements of a given list

0

Write a Python program to get all possible combinations of the elements of a given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def combinations_list(colors):
    if len(colors) == 0:
        return [[]]
    result = []
    for el in combinations_list(colors[1:]):
        result += [el, el+[colors[0]]]
    return result
colors = ['orange', 'red', 'green', 'blue']
print("Original list:")
print(colors)
print("\nAll possible combinations of the said list’s elements:")
print(combinations_list(colors))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now