BoZenKhaa
0
Q:

python lcs length

def lcs(X, Y):
  
    n = len(Y)
    m = len(X)
    
    L = [[None]*(n + 1) for i in range(m + 1)]
    for i in range(m + 1): 
        for j in range(n + 1): 
            if i == 0 or j == 0 : 
                L[i][j] = 0
            elif X[i-1] == Y[j-1]: 
                L[i][j] = L[i-1][j-1]+1
            else: 
                L[i][j] = max(L[i-1][j], L[i][j-1])
                
    return L[m][n] 
0
# to get the length of a string or array, use the len() method
my_string = "Hello World"
my_list = ["apple", "banana", "orange"]

print(len(my_string)) # outputs 11
print(len(my_list)) # outputs 3
2
# Python program to demonstrate the use of 
# len() method   

string = "Trinix" 
print(len(string)) # 6 
0

New to Communities?

Join the community