How to add repeats of the same element to list by comparing index in Python?
<p>I'm attempting to do work with lists in Python and there is a certain part I've been stuck on:</p>

<p>Objective: Iterate through a master list (alphabet) of x amount of elements, and compare whether the index of said element is a factor of 7. If so, append this element to a new list (final). It seems very simple, and here is the code I've written so far:</p>

<p>def test():</p>

<p>alphabet = ['a', 'a', 'b' 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'li', 'a']
final = []</p>

<pre><code>for letter in alphabet:
    if (alphabet.index(letter) % 7 == 0):
        final.append(letter)

print final
</code></pre>

<p>The output I am getting: ['a', 'a', 'g', 'n', 'u', 'a']</p>

<p>The output I am expecting should return a list of every element in the original list that has an index divisible by 7. I cannot figure out how to account for the duplicates.</p>

<p>Any assistance with this would be much appreciated - thank you very much in advance!</p>