How to find adjacent pairs in a sequence, python
<p>For one of my assignments, I have to write a code that will look for adjacent pairs in a sequence. If there are no pairs in the sequence, the output has to be None. Could be a list, string, whatever. The code that I have only worked for half of the test files (the true ones), yet I am having trouble passing the false test files. I am not sure what I am doing wrong and would like help to complete this task. Here is the code I am working with:</p>

<pre><code>def neighboring_twins(xs):
    twins = False
    for i in range(len(xs)):
        for j in range(i+1,len(xs)):
            if xs[i] == xs[j]:
            twins = True
     return twins
</code></pre>

<p>sample inputs:</p>

<pre><code>xs = [1,1]
</code></pre>

<p>output = <code>true</code></p>

<pre><code>xs = [2,1,2]
</code></pre>

<p>output = <code>False</code></p>

<pre><code>xs = []
</code></pre>

<p>output= <code>False</code></p>

<p>Loop through <code>xs</code> starting from the <em>second</em> item, and compare to the previous item:</p>

<pre><code>def neighboring_twins(xs):
    for i in range(1, len(xs)):
        if xs[i] == xs[i-1]:
            return True
    return False
</code></pre>

python python-3.x