2016-10-20 114 views
-1

我有一個循環,但它的遞增。遞歸循環的語法是什麼?Python遞減循環

for item2 in textPad.get(itemindex,END): 
    tagnames = textPad.tag_names(str(curline)+"."+str(curchar)) 
    if not "phpsingqoute" in tagnames and not "phpdoubqoute" in tagnames and not "phpcomment" in tagnames: 
     if item2 == theopenandclose[1]: 
      opencount -= 1 
      if opencount == 0: 
       textPad.tag_add(tagname,str(curline)+"."+str(curchar)) 
       textPad.tag_config(tagname,foreground="white",background="#000") 
       break 
     if item2 == theopenandclose[0]: 
      opencount += 1 
    if re.match(r'\n',item2): 
     curline += 1 
     curchar = -1 
    curchar += 1 

回答

0

如果textPad.get返回一個列表,你可以使用reversed

for item2 in reversed(textPad.get(itemindex,END)): 

這也將努力爲其他類型的可迭代,但不是全部。 See the documentation.如果你得到一個TypeError,嘗試textPad.get的結果轉換到列表第一:

for item2 in reversed(list(textPad.get(itemindex,END))):