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
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.
© 2024 OneMinuteCode. All rights reserved.