How to make code that's functionally similar to enumerate without actually using enumerate?
<p>I suppose to write a code that prints out the value of a number that occurs twice in the list given, but they don't allow us to use a built in function on python. How would I be able to write it without using enumerate? </p>

<pre><code>def find_second_occurrence(xs,v):
    count = 0
    value = None
    for i, x in enumerate(xs):
        if v == x:
            count += 1
            if count == 2:
                return i
    if (count &lt; 2):
        return value
</code></pre>

<p>Your own enumerate function might be something like this: </p>

<pre><code>def my_enumerate(a_list):
    result = []
    counter = 0
    for item in a_list:
        result.append((counter, item))
        counter += 1
    return result
</code></pre>

<p>Unlike the built-in <code>enumerate</code>, which is a generator that yields one item at a time, your function is returning a list. </p>

python list function python-3.x enumerate