Answer the question
In order to leave comments, you need to log in
How to find neighboring elements of a dictionary by keys?
There is a dictionary:
{'слово': 'S', 'адвокат': 'S', 'было': 'V', 'весьма': 'ADV', 'популярным': 'A', 'законодательное': 'A', 'закрепление': 'S', 'этот': 'APRO', 'термин': 'S' ...}
'А'
dictionary values and pull out their key, but only if the next word has a value of 'S'
. 'законодательное' 'закрепление'
Answer the question
In order to leave comments, you need to log in
from itertools import tee
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return zip(a, b)
keys = [k for k, v in zip(pairwise(d.keys()), pairwise(d.values())) if v == ('A', 'S')]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question