Of course, in Python, you can slice with [start:end:step], so it is valid to do list[:3:3] for double the happiness. Not that you’d ever practically do so.
You’re right, it would return a list containing the first element of the sliced list.
So:
lst[:3:3] == [lst[0]]
Well, technically a sequence containing the first element of whatever sequence you sliced. Take advantage of implementing magic methods and you too can abuse slice notation with your classes.
Of course, in Python, you can slice with [start:end:step], so it is valid to do
list[:3:3]
for double the happiness. Not that you’d ever practically do so.It’s functionally identical to
list[0]
so you could definitely just refactor your code to uselist[:3:3]
I don’t think that’s equivalent. I think the former would return
e0
and the latter would return[e0]
You’re right, it would return a list containing the first element of the sliced list.
So:
lst[:3:3] == [lst[0]]
Well, technically a sequence containing the first element of whatever sequence you sliced. Take advantage of implementing magic methods and you too can abuse slice notation with your classes.