Numbers Index¶
Given a list of integer numbers we wish to know the numbers whose position matches themselves.
You are required to deliver the following functions in the module numindex (file numindex.py).
The first function is:
- numindex_for(l)¶
such that
For example:
>>> l = [0, 2, 4, 3, 5, 7, 6, 9] >>> numindex_for(l) [0, 3, 6] >>> l = [-1, 0, 1, 2, 3, 4] >>> numindex_for(l) []
Observe that in the first example, positions 0, 3, 6 of list l have a 0, a 3 and a 6 respectively.
Warning
This function must be implement using the for sentence.
Doctests are available in the numindex_for.test file.
The second function is:
- numindex_cl(l)¶
with the same specification as numindex but it must be implemented using comprehension lists.
Warning
This function must be implement using comprehension lists.
Doctests are available in the numindex_cl.test file.