Skip to content

Instantly share code, notes, and snippets.

@jelc53
Created February 25, 2026 10:49
Show Gist options
  • Select an option

  • Save jelc53/4ee087b4956e26ee50cdac025a65eea0 to your computer and use it in GitHub Desktop.

Select an option

Save jelc53/4ee087b4956e26ee50cdac025a65eea0 to your computer and use it in GitHub Desktop.
fun recursion example to generate all combination sets of a list
def power_set(my_list):
if len(my_list) == 0:
return [[]]
power_set_without_first = power_set(my_list[1:])
with_first = [ [my_list[0]] + rest for rest in power_set_without_first ]
return with_first + power_set_without_first
universities = ['MIT', 'UCLA', 'Stanford', 'NYU']
power_set_of_universities = power_set(universities)
for set in power_set_of_universities:
print(set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment