def subs(l):
if l == []:
return [[]]
x = subs(l[1:])
return x + [[l[0]] + y for y in x]
Results:
>>> print (subs([1, 2, 3]))
[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]
More Related Contents:
- I have a list of file names and I need to be able to count how many of the same file gets repeated for each file name [closed]
- What are the advantages of NumPy over regular Python lists?
- Python List vs. Array – when to use?
- How to read a text file into a list or an array with Python
- Python recursion with list returns None [duplicate]
- Basics of recursion in Python
- How to do a recursive sub-folder search and return files in a list?
- List comprehension vs. lambda + filter
- Flatten list of lists [duplicate]
- Find nearest indices for one array against all values in another array – Python / NumPy
- Sort multidimensional array based on 2nd element of the subarray
- Get number of items from list (or other iterable) with certain condition
- Initializing a list to a known number of elements in Python [duplicate]
- How to find common elements in list of lists?
- How to read an array of integers from single line of input in python3
- Confusing […] List in Python: What is it?
- What is the ‘pythonic’ equivalent to the ‘fold’ function from functional programming?
- Implement list-like index access in Python
- List to array conversion to use ravel() function
- Numpy individual element access slower than for lists
- Generate all possible lists of length N that sum to S in Python
- How do I declare an array in Python?
- Flattening a list recursively [duplicate]
- Identify duplicate values in a list in Python
- How to access a column in a list of lists in python
- How to sort multidimensional array by column?
- Python list([]) and []
- How do I reverse a list using recursion in Python?
- Python: Elegant and efficient ways to mask a list
- Optimal method to find the max of sublist items within list