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 the number of numerical palindromes within each number. For this kata, single digit numbers will NOT be considered numerical palindromes. 

Return "Not valid" if the input is not an integer or is less than 0.

```
palindrome(5) => 0
palindrome(1221) => 2 
palindrome(141221001) => 5  
palindrome(1294) => 0
palindrome("1221") => "Not valid"

```

```Haskell
In Haskell, return a Maybe Int with Nothing for negative numbers.
```

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

Difficulty: introductory

Starter code:

def palindrome(num):
	

Solutions:
def palindrome(num):
    if not isinstance(num, int) or num < 0:
        return 'Not valid'
    s = str(num)
    return sum(sum(s[i:i+n] == s[i:i+n][::-1] for i in range(len(s)-n+1)) for n in range(2, len(s)+1))


def palindrome(num):
        
    if not isinstance(num, int) or num < 0:
        return "Not valid"
    
    c, s = 0, '?'+str(num)+'!'
    for i in range(len(s)-2):
        if s[i] == s[i+1]:
            if s[i-1] == s[i+2]: c += 2
            else: c += 1
        
        if s[i] == s[i+2]: c += 1
        
    return c

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'
    c, l = 0, len(n)
    for i in range(2, l+1):
        for j in range(l-i+1):
            c += pal(n[j:j+i])
    return c

from itertools import combinations_with_replacement as combs

def palindrome(num):
    is_palindrome = lambda chunk: chunk == chunk[::-1] and len(chunk) > 1
    s, l = str(num), len(str(num))
    return len([s[i:j] for i,j in combs(range(l+1), 2) if is_palindrome(s[i:j])]) if isinstance(num, int) and num > 0 else 'Not valid'

def palindrome(num):
    if not isinstance(num, int) or num < 0:
        return "Not valid"
    s = str(num)
    l = len(s)
    return sum(1 for p in (s[i:i+1+j] for j in range(1, l) for i in range(l-j)) if p == p[::-1])

def palindrome(num):
    cnt = 0
    if type(num) != int or num < 0:
        return "Not valid" 
    s = str(num)
    for i in range(len(s) - 1):
        for j in range(i + 1, len(s)):
            if s[i : j + 1] == s[i : j + 1][::-1]:
                cnt += 1
    return cnt

def palindrome(num):
    if type(num) != int or num < 0: return "Not valid"
    s = str(num)
    count, ls = 0, len(s)
    for i in range(ls-2):
        for d in [1,2]:
            if s[i] == s[i+d]:
                offset = 1
                while 0 <= i-offset and i+d+offset < ls and s[i-offset] == s[i+d+offset]:
                    offset += 1
                count += offset
    return count + (ls != 1 and s[-1] == s[-2])

def palindrome(num):
    if type(num) is not int or num < 0:
        return "Not valid"
    if num < 10:
        return 0
    
    counter = 0
    num = str(num)
    for i in range(0,len(num)-1):
        for r in range(i + 2, len(num)+1):
            if num[i:r] == num[i:r][::-1]:
                counter += 1    
    return counter

def palindrome(n):
    if not isinstance(n, int) or n < 0:
        return "Not valid"
    s = str(n)
    return sum(s[i:j] == s[i:j][::-1]
               for i in range(len(s) - 1)
               for j in range(i + 2, len(s) + 1))

def palindrome(num):
    return "Not valid" if not isinstance(num, int) or num < 0 else 0 if num < 10 else len([c for i, c in enumerate(str(num)[:-1]) if str(num)[i+1] == c or len(str(num)) - i > 3 and str(num)[i+3] == c or len(str(num)) - i > 2 and str(num)[i+2] == c])