human
Write me a code to count All Palindromic Subsequence in a given String and the other steps required given the following:
Count All Palindromic Subsequence in a given String | Function return the total palindromic subsequence.
Create a 2D array to store the count of palindromic subsequence.
palindromic subsequence of length 1.
check subsequence of length L is palindrome or not.
return total palindromic subsequence.
Driver program"
How can the above be solved in Python?
assistant
#Here is code to count All Palindromic Subsequence in a given String and the other steps required.
 def countPS ( str ) :
	N = len ( str )
	cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]
	for i in range ( N ) :
		cps [ i ] [ i ] = 1
	for L in range ( 2 , N + 1 ) :
		for i in range ( N ) :
			k = L + i - 1
			if ( k < N ) :
				if ( str [ i ] == str [ k ] ) :
					cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )
				else :
					cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )
	return cps [ 0 ] [ N - 1 ]
str = " abcb "
print ( " Total ▁ palindromic ▁ subsequence ▁ are ▁ : ▁ " , countPS ( str ) )