2016-03-05 35 views
-2

从未有过这样的问题,不知道如何解决,甚至把它称为...的Python for循环只有每秒项目

types = [105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007] 
for type in types: 
    print type 

只打印

105000 
105002 
105004 
105006 

但我不知道为什么。

使用函数来生成从输入像阵列

self.arrSplit(105000,105001,105002,105003,105004,105005,105006,105007) 

功能:

def arrSplit(self, arr): 
     itms = [] 
     for it in arr.split(','): 
      tt = it.split('-') 
      if (len(tt) >= 2 and int(tt[0]) < int(tt[1])): 
       for i in range(int(tt[0]), int(tt[1])+1): 
        itms.append(i) 
      else: 
       itms.append(int(tt[0])) 
     return itms 

完成此代码看起来是这样的(其最小)

types = self.arrSplit(105000,105001,105002,105003,105004,105005,105006,105007) 
print types 
for type in types: 
print type 

版画:

[105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007] 
105000 
105002 
105004 
105006 
+0

这是不可能的。你确定这是产生该输出的代码吗? – styvane

+0

对我来说工作得很好......尽管如此,你的缩进已被打破,但我想这是你如何将它放在SO上的一种人造物。SO –

+0

请给出意见(是你提到的'1,2,3,4'? ),预期的返回值和'arrSplit'的实际返回值。 –

回答

0

对于for循环,你应该这样做:

types = [105000, 105001, 105002, 105003, 105004, 105005, 105006, 105007] 
for numbers in types: 
    print numbers 

这为我工作,但我无法解释为什么它只是唇上印。