0

まず、私はこの機能を持っています:

def change_pos(a, b):
  temp = a
  a = b
  b = temp
  print 'Done'

そして、私はそれを別の関数で呼び出しますが、「完了」と出力して何もしません。私は直接コードを書きます:

a = 1
b = 2
temp = a
a = b
b = temp

それは正常に動作します。ここに何か提案はありますか?第二に、これは私のコードです

def check_exception(list):
    for element in list:
    # Take list of numbers
    # \s*: Skip space or not (\t\n\r\f\v), \d: Number [0-9]
    # ?: Non-capturing version of regular parentheses
        first = re.compile("\s*(?:\[)(\d+)\s*(?:,)").findall(element)
        last = re.compile("\s*(?:,)(\d+)\s*(?:\])").findall(element)
    # Convert string to integer
        first_int = map(int, first)
        last_int = map(int, last)

    # Check and code above works
        i = 0
        print first_int[i]
        change_pos(first_int[i],first_int[i+1])
        print first_int[i+1]
        print len(first_int)
        #print type(first_int[0])
    # Sort
        # Error: list index out of range at line 47 and more
        i = 0
        while i < len(first_int):
            if first_int[i] > first_int[i+1]:
                change_pos(first_int[i], first_int[i+1])
                change_pos(last_int[i], last_int[i+1])
            i += 1
    # Check exception
        j = 0
        while j < len(last_int):
            if last_int[j] < first_int[j+1]:
                return false
                break
            else:
                j += 1
                continue
            return true

そして、次のように表示されます: IndexError: list index out of range at conditions after # Error 助けてくれてありがとう。:)

4

3 に答える 3