min函数只打印一个结果而不是两个

时间:2016-04-01 09:26:10

标签: python-2.7 min

def Skew(Text):    
    skew = {}
    n = len(Text)
    skew[0] = 0
    for i in range(1,n+1):   
        #Every time we encounter a G, skew[i] is equal to skew[i-1]+1
        if Text[i-1] == "G": skew[i] = skew[i-1]+1
        #every time we encounter a C, Skew[i] is equal to Skew[i-1]-1
        elif Text[i-1] == "C": skew[i] = skew[i-1]-1
        #otherwise, Skew[i] is equal to Skew[i-1]
        else: skew[i] = skew[i-1]
return skew


Text = "CCGGCCGG"    
positions = [] #output variable
skew = Skew(Text)
print skew
minimum = min(skew.values()) 
print minimum
#use the for loop, to look for i when Skew[i]=minimum
for i in skew:
    if skew[i] == minimum: positions.append(i)
positions = positions[1:]
print positions

"""这是我的代码。(道歉是第一次用户),但它没有做我想要的。如果运行代码,则最小值为-2,并且有2个键为-2,因此位置应该有两个结果,而不是一个。有人可以解释为什么会一直这样吗?"""

1 个答案:

答案 0 :(得分:0)

第一个索引以0开头。



    positions = positions[0:]