0

I'm having difficulty turning tuple into indexing in order to output a new list. (I just don't mind the Python code format here, I'm sorry) For example, the input list is [0, 3, 4, 2, 1, 5] and the input tuple is (0,2) I wanna get the list of index 0 to index 2 of the input list, I mean my expected output is [0, 3, 4]. Does anyone know how to convert the tuple (0,2) into a continuous indexing to get the expected output? Here's my way to complete that:

final_list = [input_list[i] for i in input_tuple]

I knew my way to do it is wrong, I couldn't think up another way to do it. Could you guys help me out?

Reza
  • 1,945
  • 1
  • 9
  • 17
Xiangyin
  • 1
  • 2

1 Answers1

0

Try this to see if it can help:

start, end = tpl     # your tuple 

final_list = lst[start: end+1]   # lst is your input_list 
>>>final_list
[0, 3, 4]
Daniel Hao
  • 4,922
  • 3
  • 10
  • 23