I am working on a problem which is about unpacking a multi-nested list and want to understand why list slicing for this list doesn't look as expected.
Typically, both L[0] and L[:1] are the same because they both return the first element of the list.
However, if you look at the code block below, when I tested out L[0] == L[:1] the result is FALSE. The difference is that L[:1] would have another outer bracket. Can someone please explain the difference to me?
L = [['a', ['cat'], 2],[[[3]], 'dog'], 4, 5]
print(L[0])
print(L[:1])
L[0] == L[:1]
this is the output of the code above:
['a', ['cat'], 2]
[['a', ['cat'], 2]]
False