The aim of this kata is to split a given string into different strings of equal size (note size of strings is passed to the method)

Example:

    Split the below string into other strings of size #3

    'supercalifragilisticexpialidocious'

    Will return a new string
    'sup erc ali fra gil ist ice xpi ali doc iou s'


Assumptions:

    String length is always greater than 0
    String has no spaces
    Size is always positive

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def split_in_parts(s, part_length):
	

Solutions:
from textwrap import wrap

def split_in_parts(s, part_length):
	return ' '.join(wrap(s, part_length))


def split_in_parts(s, n):
	return ' '.join([s[i:i + n] for i in range(0, len(s), n)])


def split_in_parts(s, part_length):
	new = ''
	i = 0
	for x in s:
		if i == part_length:
			new += ' '
			new += x
			i = 1
		else:
			new += x
			i += 1
	return new


def split_in_parts(s, p):
	return ' '.join((s[i:i + p] for i in range(0, len(s), p)))


def split_in_parts(s, p):
	l = []
	i = 0
	while i < len(s):
		k = s[i:i + p]
		l.append(k)
		i += p
	res = ' '.join(l)
	return res


def split_in_parts(s, part_length):
	newS = ''
	for i in range(len(s)):
		newS += f' {s[i]}' if i != 0 and i % part_length == 0 else s[i]
	return newS


def split_in_parts(stg, size):
	return ' '.join((stg[i:i + size] for i in range(0, len(stg), size)))


def split_in_parts(s, part_length):
	cnt = 0
	answer = ''
	for i in s:
		if cnt < part_length:
			answer += i
			cnt += 1
		else:
			answer = answer + ' ' + i
			cnt = 1
	return answer


def split_in_parts(s, part_length):
	r = []
	for x in range(0, len(s), part_length):
		r += [s[x:x + part_length]]
	return ' '.join(r)