You are going to be given a string. Your job is to return that string in a certain order that I will explain below:

Let's say you start with this: `012345`

The first thing you do is reverse it:`543210`  
Then you will take the string from the 1st position and reverse it again:`501234`  
Then you will take the string from the 2nd position and reverse it again:`504321`  
Then you will take the string from the 3rd position and reverse it again:`504123`

Continue this pattern until you have done every single position, and then you will return the string you have created. For this particular number, you would return:`504132`

#Input:
A string of length 1 - 1000

#Output:
A correctly reordered string.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def reverse_fun(n):
	

Solutions:
def reverse_fun(n):
	for i in range(len(n)):
		n = n[:i] + n[i:][::-1]
	return n


def reverse_fun(n):
	l = len(n)
	return ''.join((b + a for (a, b) in zip(list(n[:l // 2]) + [''], n[l // 2:][::-1])))


def reverse_fun(n, first=False):
	return '' if len(n) < 1 else n[0] + reverse_fun(n[1:]) if first else n[-1] + reverse_fun(n[:-1], True)


from itertools import zip_longest

def merge(sequences, fillvalue=None):
	for slice in zip_longest(*sequences, fillvalue=fillvalue):
		for item in slice:
			yield item

def reverse_fun(text):
	mid = len(text) // 2
	return ''.join(merge((text[:mid - 1:-1], text[:mid]), fillvalue=''))


def reverse_fun(n):
	string = ''
	for i in range(len(n)):
		string += n[::-1][0]
		n = n[::-1][1:]
	return string


from itertools import chain, zip_longest

def reverse_fun(n):
	l = len(n) >> 1
	return ''.join(chain.from_iterable(zip_longest(n[:l - 1:-1], n[:l], fillvalue='')))


def reverse_fun(n):
	from collections import deque as dq
	n = dq(n)
	n_dq = dq()
	for i in range(len(n)):
		if i == 0 or i % 2 == 0:
			n_dq.append(n.pop())
		elif i % 2 != 0:
			n_dq.append(n.popleft())
	return ''.join(n_dq)


def reverse_fun(arr):
	for i in range(len(arr)):
		arr = arr[0:i] + arr[i:][::-1]
	return arr