Basic Recursion
Given a possibly nested sequence and an item, count the occurrences of the item in the sequence.
For instance given,
[1, [2, 3], 4, [5, [6, 4]]]
you should be able to count 2 occurrences of 4.
Use recursion.
Map a possibly nested sequence to its flattened version, which comprises only the ground element. For example, the sequence
[1, [2, 3], 4, [5, [6, 7]]]
should be mapped to
[1, 2, 3, 4, 5, 6, 7]
Use recursion.
Write a function that takes an object and a sequence and returns the index of the item in the sequence, starting from 0. If the item does not occur in the sequence, return -1.
Use recursion.
Given a set of items provided as a list, write a function that returns the power set of the given set.
Use recursion.
Given a possibly nested list, compute the deepest level of embedding in the list. The ground level counts as 0 depth. For example, the list T
[1, [2, 3], 4, [5, [6, 7]]]
should return 2.
Use recursion.
Take a possibly nested list of items, a test function, and a transformation
function, Return a list identical to the input list except that the items
passing the test functions are altered with the transformation function. For
example, if the input list is [[1, 2], [3, 4]], the test function is lambda
x: x % 2 == 0, and the transformation function is lambda x: x * 2, then the
output should be [[1, 4], [3, 8]].