To specify indexes in order when the list has duplicate values

Asked 2 years ago, Updated 2 years ago, 36 views

a= [Seoul, Seoul, Gyeonggi, Gyeonggi, Gyeonggi, Incheon, Incheon] b=[Game, game, game] How do we find the number of indexes in a that are the data in b?

list

2022-09-21 20:10

1 Answers

a=["Seoul", "Seoul", "Seoul", "Gyeonggi", "Gyeonggi", "Incheon", "Incheon"]
b=["Game", "Game", "Game"]

To find ['match', 'match', 'match'] in the list of a

The list of a should be grouped like ['Seoul', 'Seoul', 'Seoul'], ['Gyeonggi', 'Gyeonggi', 'Gyeonggi'], ['Incheon', 'Incheon', 'Incheon'].

>>> a=['Seoul', 'Seoul', 'Seoul', 'Gyeonggi', 'Gyeonggi', 'Gyeonggi', 'Incheon', 'Incheon']
>>> b=['match', 'match', 'match']
>>> [list(v) for k, v in itertools.groupby(a)].index(b)
1

You can get it in the same way.


2022-09-21 20:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.