Given a list, start and end index, we have to create a list from specified index of the list in Python.
给定一个列表,开始和结束索引,我们必须根据Python中列表的指定索引创建一个列表。
Example 1:
范例1:
Input:
list : [10, 20, 30, 40, 50, 60]
start = 1
end = 4
Logic to create list with start and end indexes:
List1 = list[start: end+1]
Output:
list1: [20, 30, 40, 50]
Example 2:
范例2:
Input:
list : [10, 20, 30, 40, 50, 60]
start = 1
end = 6
Logic to create list with start and end indexes:
list1 = list[start: end+1]
Output:
Invalid end index
Logic:
逻辑: