Checking if a sequence has consecutive identical characters
<p>For this function I'm trying to have it return "True" when a sequence has consecutive identical characters and have it return "False" when a sequence doesn't. For example, <code>neighboring_twins(1,2,1,4,1)</code> should return <code>False</code> while <code>neighboring_twins(1,2,3,3,5)</code> should return <code>True</code> because there are two identical characters directly next to each other (the two 3's). </p>

<p>This is the code I have so far. I don't think having Python search for <code>"ii"</code> is the right way to do it as I keep getting syntax errors. I wasn't sure how I would instruct Python to search for consecutive identical characters but assumed I should use a for loop.</p>

<pre><code>def neighboring_twins(xs):

    for i in xs:
        if ii = True
            return True
        elif ii = False
            return False
</code></pre>

<p>Edit: I'd like to accomplish this without importing from other modules and in the simplest way possible.</p>

<p>You are getting syntax errors because <code>if ii</code> is asking the Python interpreter to check the variable <code>ii</code> and see if it's true or not. I would recommend iterating through the list and checking the next element to see if it equals the next. <code>enumerate()</code> will be useful for you.</p>

<p>I also noticed that you're using <code>if ii = True</code> which is assigning the value of True to ii instead of checking if <code>ii</code> is True. You probably want <code>if ii == True</code>. The <code>==</code> checks for equality and a single equals sign assigns a value to a variable.</p>

python loops character sequence