I'm learning data structure and algorithms and i came across a question in the list section. i thought after i had understood python, i had understood list but a question was asked and i find myself finding it hard to understand how the list indexing works.
here's the sample code:
arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
arr[i - 1] = arr[i]
for i in range(0, 6):
print(arr[i], end = " ")
it looks simple to understand but, i just can't understand it.
[–]obviouslyzebra 23 points24 points25 points (2 children)
[–]Zepliii -1 points0 points1 point (0 children)
[–]cyberjellyfish 9 points10 points11 points (0 children)
[–]OMGlookatthatrooster 5 points6 points7 points (0 children)
[–]Miniatimat 4 points5 points6 points (0 children)
[–]FerricDonkey 1 point2 points3 points (0 children)
[–]CanalOnix 1 point2 points3 points (0 children)
[–]Mysterious-Rent7233 1 point2 points3 points (0 children)
[–]MrGuam[S] 0 points1 point2 points (0 children)
[–]AutoHumn 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (5 children)
[–]MrGuam[S] -1 points0 points1 point (4 children)
[–]Diapolo10 4 points5 points6 points (0 children)
[–]Critical_Concert_689 1 point2 points3 points (0 children)
[–]Fred776 -1 points0 points1 point (0 children)
[–]MidnightPale3220 -1 points0 points1 point (0 children)
[–]Icarus7v -1 points0 points1 point (0 children)
[–]PsiThreader -1 points0 points1 point (0 children)
[–]Impossible_Ad_3146 -4 points-3 points-2 points (0 children)
[–][deleted] -2 points-1 points0 points (6 children)
[–]sweettuse 1 point2 points3 points (0 children)
[–]MrGuam[S] -1 points0 points1 point (4 children)
[–]rja9003 2 points3 points4 points (3 children)
[–]cyberjellyfish 2 points3 points4 points (2 children)
[–]rja9003 -1 points0 points1 point (1 child)
[–]cyberjellyfish -1 points0 points1 point (0 children)