该问题与解决方案一起发布。但我不明白解决方案,尤其是在 for 循环中。有人可以为我详细说明代码吗?
[1]: https://i.stack.imgur.com/p1Lkp.jpg 
该问题与解决方案一起发布。但我不明白解决方案,尤其是在 for 循环中。有人可以为我详细说明代码吗?
[1]: https://i.stack.imgur.com/p1Lkp.jpg 
在这里,我尝试对您发布的问题进行一些解释。
实际上,如果您可以通过平台运行它来查看程序的运行情况会更容易 - http://pythontutor.com/ 下次。
# 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)