Computer Science

What's a[1 : 1] if a is a list of at least two elements? And what if the list is shorter?

Python List Manipulation

45 Likes

Answer

a[x:y] returns a slice of the sequence from index x to y - 1. So, a[1 : 1] will return an empty list irrespective of whether the list has two elements or less as a slice from index 1 to index 0 is an invalid range.

Answered By

22 Likes


Related Questions