Program - Given a list slice it into a 3 equal chunks and revert each list


Topic: Program - Given a list slice it into a 3 equal chunks and revert each list

Solution

sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]
length = len(sampleList)
chunkSize  = int(length/3)
start = 0
end = chunkSize
for i in range(1, 4, 1):
  indexes = slice(start, end, 1)
  listChunk = sampleList[indexes]
  mylist = [i for i in listChunk]
  print("After reversing it ", mylist)
  start = end
  if(i != 2):
    end +=chunkSize
  else:
    end += length - chunkSize



List all Python Programs