Arrays Python使用for循环排列列表

Arrays Python使用for循环排列列表,arrays,list,loops,for-loop,alternating,Arrays,List,Loops,For Loop,Alternating,问题和解决方案已发布。但我不理解解决方案,尤其是在for循环中。谁能给我详细解释一下密码吗 [1] :图片描述在此]()在此,我尝试对您发布的问题进行一些解释。 事实上,如果你能在平台上运行它来查看下一次运行的程序,会更容易 # interleave a list items: # array = [3, 6, 1, 2, 'a', 'c', 'b', 'z'] # 0 1 2 3 4 5 6 7 N = len(array) # the len

问题和解决方案已发布。但我不理解解决方案,尤其是在for循环中。谁能给我详细解释一下密码吗


[1] :图片描述在此]()

在此,我尝试对您发布的问题进行一些解释。
事实上,如果你能在平台上运行它来查看下一次运行的程序,会更容易

# interleave a list items:
#

array = [3, 6, 1, 2, 'a', 'c', 'b', 'z']
#        0  1  2  3   4    5    6   7

N = len(array)    # the length of the array a

out =  []         # to stort the output

c = mid = N //2   # mid-point of the array
print(f' c: {c} ')  

for item in array:
    if c != N:
        print(array[c])
        
        out += [item] + [array[c]]   # get 4th item - 'a', append it; then continue

        c += 1   # moving this mid-point
        print(f' c is {c} ')

print(out)

哪一部分你不明白?请输入您的代码,而不是问题的图像。