Given an array, return the reversed version of the array (a different kind of reverse though), you reverse portions of the array, you'll be given a length argument which represents the length of each portion you are to reverse.

E.g
  
  if after reversing some portions of the array and the length of the remaining portion in the array is not up to the length argument, just reverse them.
  

`selReverse(array, length)`

- array - array to reverse
- length - length of each portion to reverse

Note : if the length argument exceeds the array length, reverse all of them, if the length argument is zero do not reverse at all.

Difficulty: introductory

Starter code:

def sel_reverse(arr,l):
	

Solutions:
def sel_reverse(arr,l):
    return [ elt for i in range(0, len(arr), l) for elt in arr[i:i+l][::-1] ] if l != 0 else arr

from itertools import chain

def gen(arr, l):
    for i in range(0, len(arr), l):
        yield arr[i:i+l][::-1]

def sel_reverse(arr,l):
    return list(chain.from_iterable(gen(arr, l or 1)))

def sel_reverse(arr,l):
    new_l = []
    index = max(l, 1)
    for x in range(0, len(arr)+1, max(index,l)):
        new_l.extend(arr[x:x+index][::-1])
    return new_l

def sel_reverse(lst, k):
    return sum((lst[i:i+k][::-1] for i in range(0, len(lst), k)), []) if k else lst
    
    

# alternative:
#    return [e for i in range(0, len(lst), k) for e in lst[i:i+k][::-1]] if k else lst


def sel_reverse(arr, l):
    l = l or 1
    return [
        x
        for i in range(0, len(arr), l)
        for x in reversed(arr[i:i+l])
    ]

def sel_reverse(arr,l):
    return sum([arr[i:i+l][::-1] for i in range(0,len(arr),l)],[]) if l>0 else arr

def sel_reverse(arr,l):
    #your code here
    res = []
    
    if l == 0:
      return arr
      
    i = 0
    while i < len(arr):
      res.append(arr[i:i+l][::-1])
      i += l
    
    return sum(res, [])

def sel_reverse(arr,l):
    if not l:
        return arr
    arr = [sorted(arr[i: i + l])[::-1] for i in range(0, len(arr), l) ]
    return [j for i in arr for j in i]

from itertools import zip_longest,chain

def sel_reverse(arr,l):
    if l==0: return arr
    return [e for e in chain.from_iterable(t[::-1] for t in zip_longest(*[iter(arr)]*l)) if e is not None]

def sel_reverse(arr, l):
    return [y for x in [arr[i:i + l][::-1] for i in range(0, len(arr), l)] for y in x] if l else arr