A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: `2332, 110011, 54322345`

For a given number ```num```, write a function which returns an array of all the numerical palindromes contained within each number. The array should be sorted in ascending order and any duplicates should be removed.

In this kata, single digit numbers and numbers which start or end with zeros (such as `010` and `00`) are **NOT** considered valid numerical palindromes.  

If `num` contains no valid palindromes, return `"No palindromes found"`. 
Otherwise, return `"Not valid"` if the input is not an integer or is less than `0`.


## Examples

```
palindrome(1221)      =>  [22, 1221]
palindrome(34322122)  =>  [22, 212, 343, 22122]
palindrome(1001331)   =>  [33, 1001, 1331]
palindrome(1294)      =>  "No palindromes found"
palindrome("1221")    =>  "Not valid"
```

---

### Other Kata in this Series:

Numerical Palindrome #1
Numerical Palindrome #1.5
Numerical Palindrome #2
Numerical Palindrome #3
Numerical Palindrome #3.5
Numerical Palindrome #4
Numerical Palindrome #5

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def palindrome(num):
	

Solutions:
def palindrome(num):
	if not isinstance(num, int) or num < 0:
		return 'Not valid'
	n = str(num)
	l = len(n)
	result = {int(n[i:j]) for i in range(l - 1) for j in range(i + 2, l + 1) if int(n[i]) and n[i:j] == n[i:j][::-1]}
	return sorted(result) if result else 'No palindromes found'


pal = lambda s: all((a == b for (a, b) in zip(s[:len(s) // 2], s[::-1])))

def palindrome(num):
	if type(123) != type(num):
		return 'Not valid'
	n = str(num)
	if any((not c.isdigit() for c in n)):
		return 'Not valid'
	(R, l) = ([], len(n))
	for i in range(2, l + 1):
		for j in range(l - i + 1):
			t = n[j:j + i]
			if pal(t) and t[0] != '0':
				R.append(int(t))
	return sorted(set(R)) if R else 'No palindromes found'


def is_pal(s):
	h = len(s) // 2
	return all((a == b for (a, b) in zip(s[:h], s[::-1][:h])))

def palindrome(num):
	if not isinstance(num, int) or num < 0:
		return 'Not valid'
	s = str(num)
	pals = set()
	for (i, ch) in enumerate(s):
		if ch == '0':
			continue
		for j in range(i + 2, len(s) + 1):
			test = s[i:j]
			if is_pal(test):
				pals.add(test)
	return sorted((int(x) for x in pals)) or 'No palindromes found'


from itertools import combinations_with_replacement as combs

def palindrome(num):
	is_palindrome = lambda chunk: chunk == chunk[::-1] and len(chunk) > 1 and (not (chunk.startswith('0') or chunk.endswith('0')))
	(s, l) = (str(num), len(str(num)))
	if isinstance(num, int) and num > 0:
		lst = list(set((int(s[i:j]) for (i, j) in combs(range(l + 1), 2) if is_palindrome(s[i:j]))))
	else:
		return 'Not valid'
	return sorted(lst) if len(lst) else 'No palindromes found'


def palindrome(num):
	if not isinstance(num, int) or num < 0:
		return 'Not valid'
	k = []
	s = str(num)
	for (i, x) in enumerate(s):
		string = [x]
		for j in s[i + 1:]:
			string.append(j)
			if string == string[::-1] and ''.join(string) not in k and (string[-1] != '0'):
				k.append(''.join(string))
	return k and sorted((int(x) for x in k)) or 'No palindromes found'


def palindrome(num):
	if not (isinstance(num, int) and num > 0):
		return 'Not valid'
	s = str(num)
	result = set()
	for i in range(0, len(s) - 1):
		for j in range(i + 2, len(s) + 1):
			if s[i] == '0':
				continue
			x = s[i:j]
			if x == x[::-1]:
				result.add(int(x))
	if result:
		return sorted(result)
	return 'No palindromes found'


def palindrome(n):
	if type(n) != int or n < 0:
		return 'Not valid'
	(n, p) = (str(n), set())
	for i in range(len(n)):
		for j in range(i + 2, len(n) + 1):
			sub = n[i:j]
			if sub == sub[::-1] and sub[0] != '0' != sub[-1]:
				p.add(sub)
	return sorted(map(int, p)) or 'No palindromes found'


def palindrome(num):
	if type(num) != int:
		return 'Not valid'
	elif num < 0:
		return 'Not valid'
	else:
		l = list(str(num))
		pals = []
		for i in range(len(l)):
			r_l = l[i + 1:]
			for j in range(len(r_l)):
				seq = l[i:i + 1] + r_l[:j + 1]
				print(seq)
				if len(seq) % 2 == 0:
					mid = int(len(seq) / 2)
					fr = seq[:mid]
					bk = seq[mid:][::-1]
				else:
					mid = len(seq) // 2
					fr = seq[:mid]
					bk = seq[mid + 1:][::-1]
				if fr == bk:
					pal = int(''.join(seq))
					if pal % 10 != 0 and pal not in pals:
						pals.append(pal)
		if pals:
			return sorted(pals)
		else:
			return 'No palindromes found'


def check_array(array):
	if len(array) > 1:
		mid = int(len(array) / 2)
		if len(array) % 2 == 0:
			mid = int(len(array) / 2)
			first = array[:mid]
			second = array[mid:]
		else:
			first = array[:mid]
			second = array[mid + 1:]
		second.reverse()
		if first == second:
			str_arr = ''
			for i in array:
				str_arr += str(i)
			pal = int(str_arr)
			pal2 = str(pal)
			if pal2 == str_arr:
				return pal

def palindrome(num):
	if isinstance(num, int) != True or num < 0:
		return 'Not valid'
	if num < 10:
		return 'No palindromes found'
	array = []
	for i in str(num):
		array.append(int(i))
	array_list = []
	for i in range(len(array)):
		part = array[i:]
		p = check_array(part)
		if p != None and p != 0:
			array_list.append(p)
		for j in range(len(part)):
			back = part[:-j]
			b = check_array(back)
			if b != None and b != 0:
				array_list.append(b)
	array_set = set(array_list)
	result = list(array_set)
	result.sort()
	if len(result) == 0:
		return 'No palindromes found'
	else:
		return result


def palindrome(num):
	if not isinstance(num, int) or num < 0:
		return 'Not valid'
	check = str(num)
	total = set()
	for i in range(2, len(check) + 1):
		for j in range(len(check) - i + 1):
			if check[j:j + i][0] == '0' or check[j:j + i][-1] == '0':
				continue
			if is_palin(check[j:j + i]):
				total.add(int(check[j:j + i]))
	return sorted(total) if total else 'No palindromes found'

def is_palin(s):
	return s[::-1] == s