Write a function that takes a list of at least four elements as an argument and returns a list of the middle two or three elements in reverse order.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def reverse_middle(lst):
	

Solutions:
def reverse_middle(lst):
	l = len(lst) // 2 - 1
	return lst[l:-l][::-1]


def reverse_middle(a):
	l = len(a) // 2
	return a[-l:l - 2:-1]


def reverse_middle(lst):
	return lst[len(lst) // 2 - 1:len(lst) // 2 + 1 + (1 if len(lst) % 2 != 0 else 0)][::-1]


def reverse_middle(l):
	return l[len(l) // 2 - 1:(len(l) + 3) // 2][::-1]


reverse_middle = lambda a: a[len(a) + 1 >> 1:(len(a) >> 1) - 2:-1]


def reverse_middle(lst):
	middle = int(len(lst) / 2)
	if len(lst) % 2 > 0:
		return list(reversed(lst[middle - 1:middle + 2]))
	else:
		return list(reversed(lst[middle - 1:middle + 1]))