P
P
PILITYXXX1232020-08-14 10:58:16
Python
PILITYXXX123, 2020-08-14 10:58:16

How to get values ​​from a list in a range?

There is a list:

['один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь']

And there are 2 variables:

test1 ='два'
test2 ='шесть'

You need to get a list with values ​​in the range of variables (including them):

[ 'два', 'три', 'четыре', 'пять', 'шесть']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-08-14
@PILITYXXX123

a = ['один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь']
b = a[a.index(test1):a.index(test2)+1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question