0

Please elaboarate the following lines of code

def lcs(X , Y):
    # find the length of the strings
    m = len(X)
    n = len(Y)

    l = [[None] * (n + 1) for i in xrange(m + 1)]
3
  • Have you executed the code to see what the value of l is? Commented Mar 17, 2017 at 14:54
  • Assuming the line you're asking about is the last one, what confuses you? The multiplication on a list? The list comprehension? This is pretty straightforward, if useless, Python code. Commented Mar 17, 2017 at 15:03
  • actually it is the part of the solution of longest common subsequence Commented Mar 18, 2017 at 1:09

1 Answer 1

1

I would advise you to adopt ways to figure this out yourself.

edit1: First thing you do is print(l) and see whats up.

This is a pythonesque way of creating arrays:

l = [[None]*(n+1) for i in xrange(m+1)]

and it could be written

l = []
for i in xrange( m + 1 ):
    l.append( [None]*(n+1) )

now its clearer right?

and then you could try to print( [None] * 3 ) to see what this does.

and since the comment says len of strings. then X and Y are strings.

then pass some strings to the function and see what comes out :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.