Home > other >  how to search elements of list in another nested list?
how to search elements of list in another nested list?

Time:09-27

verb_list=[['was', 'playing'], ['watches'], ['guesses'], ['washes'], ['are', 'enjoying'], ['enjoy', 'playing'], ['are', 'wearing'], ['were', 'throwing']]

verb_list list shows verbs of multiple sentences confined in it.

be_verb=['be','am','is','are','was','were','being']

be_verb list shows self-created auxiliary verb list.

I've to search "be_verb" elements in "verb_list" and create a separate list of singular and plural verbs wrt to each sentence.

CodePudding user response:

for list in verb_list:
    for word in list:
        Current_word = word
        for verb in be_verb:
            Current_verb = verb
            if Current_word == Current_verb:
                print(Current_word, " is a verb to be")
            else:
                continue

Try this out

CodePudding user response:

One-liner list comprehension

verbs = [verb[1] for verb in verb_list if verb[0] in be_verb]
  • Related