Python Minimum Skew function
<p>I used following code to find MinimumSkew:</p>

<pre><code>genome = "TAAAGACTGCCGAGAGGCCAACACGAGTGCTAGAACGAGGGGCGTAAACGCGGGTCCGAT"

def Skew(genome):    
Skew = {}

Skew[0] = 0
for i in range(1, len(genome)+1):
    if genome[i - 1] == "G":
        Skew[i] = Skew[i - 1] + 1
    elif genome[i - 1] == "C":
        Skew[i] = Skew[i - 1] - 1
    else:
        Skew[i] = Skew[i-1]
return Skew
Skew(genome)


def MinimumSkew(genome):

positions = [] # output variable
s = Skew(genome)
m = min(s.values())
for (k,v) in s.items():
    if v == m:
        positions.append(k)
        return positions
print(MinimumSkew(genome))
</code></pre>

<p>I keep getting the error:
Failed test #5. Your code did not find all minimum skew indices.</p>

<p>Test Dataset:
CCGGCCGG</p>

<p>Your output:
[11]
2</p>

<p>Correct output:
2 6
Can anyone help me what I am doing wrong?</p>

<p>There are much easier solutions to calculate skew. Here is one approach:</p>

<pre><code>def skew(genome):
    res = []
    cntr = 0
    res.append(cntr)
    for i in genome:
        if i == 'C':
            cntr -= 1
        if i == "G":
            cntr += 1
        res.append(cntr)
    return [str(i) for i, j in enumerate(res) if j == min(res)]

print(skew('CCGGCCGG')) # returns ['2', '6']
</code></pre>

<p>And your solutions is good as well, you just need to fix the indentation:</p>

<pre><code>genome = "CCGGCCGG"

def Skew(genome):
    Skew = {}

    Skew[0] = 0
    for i in range(1, len(genome)+1):
        if genome[i - 1] == "G":
            Skew[i] = Skew[i - 1] + 1
        elif genome[i - 1] == "C":
            Skew[i] = Skew[i - 1] - 1
        else:
            Skew[i] = Skew[i-1]
    return Skew


def MinimumSkew(genome):

    positions = [] # output variable
    s = Skew(genome)
    m = min(s.values())
    for (k,v) in s.items():
        if v == m:
            positions.append(k)
    return positions
print(MinimumSkew(genome))
</code></pre>

<p>This returns <code>[2, 6]</code></p>

python