Given an integer, if the length of it's digits is a perfect square, return a square block of sqroot(length) * sqroot(length). If not, simply return "Not a perfect square!".

Examples:

1212 returns:

>1212  

Note: 4 digits so 2 squared (2x2 perfect square). 2 digits on each line.

123123123 returns: 
>123123123

Note: 9 digits so 3 squared (3x3 perfect square). 3 digits on each line.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def square_it(digits):
	

Solutions:
def square_it(digits):
	s = str(digits)
	n = len(s) ** 0.5
	if n != int(n):
		return 'Not a perfect square!'
	n = int(n)
	return '\n'.join((s[i * n:i * n + n] for i in range(int(n))))


square_it = lambda n: len(str(n)) ** 0.5 % 1 and 'Not a perfect square!' or '\n'.join(map(''.join, zip(*[iter(str(n))] * int(len(str(n)) ** 0.5))))


square_it = lambda d: 'Not a perfect square!' if len(str(d)) ** 0.5 % 1 else ''.join((str(d)[i:i + int(len(str(d)) ** 0.5)] + '\n' for i in range(0, len(str(d)), int(len(str(d)) ** 0.5))))[:-1]


def square_it(digits):
	digits = str(digits)
	l = int(len(digits) ** 0.5)
	if l ** 2 == len(digits):
		return '\n'.join((digits[i * l:i * l + l] for i in range(l)))
	else:
		return 'Not a perfect square!'


import math

def square_it(digits):
	strdigits = str(digits)
	sq = math.sqrt(len(strdigits))
	if round(sq, 0) == sq:
		arr = []
		sqint = int(sq)
		for a in range(0, sqint):
			line = ''
			for b in range(0, sqint):
				line += strdigits[a * sqint + b]
			arr.append(line)
		return '\n'.join(arr)
	else:
		return 'Not a perfect square!'


def square_it(digits):
	d = len(str(digits)) ** 0.5
	return '\n'.join(map(''.join, zip(*[iter(str(digits))] * int(d)))) if int(d) == d else 'Not a perfect square!'


from re import findall

def square_it(digits):
	digits_string = str(digits)
	root = len(digits_string) ** 0.5
	if root.is_integer():
		return '\n'.join(findall('.{' + str(int(root)) + '}', digits_string))
	return 'Not a perfect square!'