P
P
PILITYXXX1232020-08-14 23:14:19
Python
PILITYXXX123, 2020-08-14 23:14:19

How to deal with 2 Python lists?

I have code -

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

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


This code prints the values ​​in the range of variables tets1 and test2 including them. That is ['two', 'three', 'four', 'five', 'six']

But I also have a list -
['2020-07-01', '2020-07-02', '2020- 07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07- 09', '2020-07-10', '2020-07-11', '2020-07-12']

I need to get values ​​from it with the same index as from the list a = ['one', 'two ', 'three', 'four', 'five', 'six', 'seven']

That is, the result should be - ['2020-07-02', '2020-07-03', '2020-07- 04', '2020-07-05', '2020-07-06']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-08-14
@PILITYXXX123

Didn't understand anything.
Why can't you just write:

test1 ='два'
test2 ='шесть'
a = ['один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь']
c = ['2020-07-01', '2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09', '2020-07-10', '2020-07-11', '2020-07-12']
b = a[a.index(test1):a.index(test2)+1]
d = c[a.index(test1):a.index(test2)+1]
print(b)
print(d)

and to get
['two', 'three', 'four', 'five', 'six']
['2020-07-02', '2020-07-03', '2020-07-04', '2020-07 -05', '2020-07-06']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question