0

I am completely new to programming so excuse my little knowledge. I want to get certain items from a list. For example:

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pick_1 = 3
pick_2 = 8
number_in_between = ...

I want the result to be:

numbers_in_between = 4, 5, 6, 7

I think i should use the index function but haven't been able to figure out how yet. Any help is welcomed.

David
  • 69
  • 1
  • 8
  • 1
    Do not name your list `list` as it is the builtin constructor name, and do `number_in_between = values[pick_1:pick_2 - 1]` – azro Oct 14 '20 at 18:28
  • This does not answer the question, if the list is not sorted, and the OP meant to search between values, not keys - which isn't clear. In this case you should find the indexes of the 2 numbers, and slice the list at the indexes. – nagyl Oct 14 '20 at 18:38
  • When I slice the list at the indexes it includes the first picked number (3). Is there a way around this? ! nevermind, I put the actual number, not the index of the number. ! – David Oct 14 '20 at 18:46
  • @David It should not add that number, but add +1 to the first number. – nagyl Oct 14 '20 at 18:48
  • Thank you for the help. – David Oct 14 '20 at 18:49

0 Answers0