Skip to main content
added 494 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

According to spec:

Stored in each element of the matrix should be a tuple, (cost, operation), where cost is an int and operation is an Operation.

So what does the line of code mean?. Means that we assign the values of the tuple to two variables but the first of them is ignored, only the second value is of interest to us. Sometimes this technique to ignore specific values is called "I do not care" and is a little-known curiosity of python.

Regarding prev [: i] is not more than a slice, a matrix that goes from the beginning (index zero) to the index i (not including)

In response to Blauelf's comment, I do not find official documentation, that is, a Python feature (I'm not a great python expert, but rather an apprentice). I would say that, more than a convention, it is a technique used by more expert programmers than me, to see clearly how it works we can see it with a simpler example:

# Ignore a value when unpacking
x, _, y = (1, 2, 3) # x = 1, y = 3 

# Ignore the multiple values.
x, *_, y = (1, 2, 3, 4, 5) # x = 1, y = 5 

According to spec:

Stored in each element of the matrix should be a tuple, (cost, operation), where cost is an int and operation is an Operation.

So what does the line of code mean?. Means that we assign the values of the tuple to two variables but the first of them is ignored, only the second value is of interest to us. Sometimes this technique to ignore specific values is called "I do not care" and is a little-known curiosity of python.

Regarding prev [: i] is not more than a slice, a matrix that goes from the beginning (index zero) to the index i (not including)

According to spec:

Stored in each element of the matrix should be a tuple, (cost, operation), where cost is an int and operation is an Operation.

So what does the line of code mean?. Means that we assign the values of the tuple to two variables but the first of them is ignored, only the second value is of interest to us. Sometimes this technique to ignore specific values is called "I do not care" and is a little-known curiosity of python.

Regarding prev [: i] is not more than a slice, a matrix that goes from the beginning (index zero) to the index i (not including)

In response to Blauelf's comment, I do not find official documentation, that is, a Python feature (I'm not a great python expert, but rather an apprentice). I would say that, more than a convention, it is a technique used by more expert programmers than me, to see clearly how it works we can see it with a simpler example:

# Ignore a value when unpacking
x, _, y = (1, 2, 3) # x = 1, y = 3 

# Ignore the multiple values.
x, *_, y = (1, 2, 3, 4, 5) # x = 1, y = 5 
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

According to spec:

Stored in each element of the matrix should be a tuple, (cost, operation), where cost is an int and operation is an Operation.

So what does the line of code mean?. Means that we assign the values of the tuple to two variables but the first of them is ignored, only the second value is of interest to us. Sometimes this technique to ignore specific values is called "I do not care" and is a little-known curiosity of python.

Regarding prev [: i] is not more than a slice, a matrix that goes from the beginning (index zero) to the index i (not including)