So I’m taking a quiz and the first question asks something that was never written or spoken once in the section on lists as they pertain to slicing… which is absolutely infuriating as I am someone who tries to understand EVERYTHING before moving on:
What are the values of
list_cafter the following snippet?
- list_a = [1, 2, 3]
- list_b = list_a[-2:-1]
- list_c = list_a[-1:-2]
To me this answer would be:
list_b = [2,3]
list_c = [3,2]
… but that is not one of the answer given:
Incorrect answer. Please try again.
list_a[-2:-1] means “start at the last but one element (inclusive) and go until the last element (exclusive)”, which essentially means “take the second element from the end”. The other slice, [-1:-2], doesn’t make sense because it starts with a higher index and finishes with a lower one, so it returns an empty slice.
So apparently the higher index, say “4” out of indexes 0,1,2,3,4 can NEVER be placed before a lower index like “2” in a result? What kind of rule is that? What is the purpose of that rule? What other nonsense rules are out there I need to be aware of “4 dimensional nested loops only work if the unicode characters are entered during a waxing moon phase while eating a peanut butter and jelly sandwich?”