.length python code example
Example 1: len python
mystring = 'Hello'
len(mystring)
mylist = ['Hello', 'Goodbye', 'Morning']
len(mylist)
Example 2: length of a string python
string = "geeks"
print(len(string))
string = "geeks for geeks"
print(len(string))
Example 3: python length
my_string = "Hello World"
my_list = ["apple", "banana", "orange"]
print(len(my_string))
print(len(my_list))
Example 4: 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]