Python3 - Find matching words in a list

I have 2 lists.

list 1 (list) - list containing descriptive text
list 2 (list) - text entered by user

I am trying to write some code at Python and I want to check if words from a list of words contain in a list 1

except searching words in text, I need to count numbers of IDs and print result.
I’m new to this and I couldn’t find anything on Google that could help me.


list = [['ID127', 'Along with their associated islands, they cover 8% of Earth's total surface area and 28.4% of its land area', 'Europe', 'Germany'],
    ['ID128', 'The first university east of France and north of the Alps was the сharles university in Prague established in 1347', 'Europe', 'Hungary'],
    ['ID129', 'The сentral European university (CEU) is a graduate-level', 'United States', 'Canada']]

text entered by user = ['area' 'university' 'сentral']

the result of the program: the word found in the text, the number of ID, region, state

program result = [area, 1, 'Europe', 'Germany'] , [university, 2, 'Europe', 'Hungary'] , [university, 2, 'United States', 'Canada'], [сentral, 2, 'United States', 'Canada']

We can help, but i am not going to write the entire program for you. What do you have so far? what can i do for you?

python has a built-in count function:

which should really help you.


if text entered by user in list:
print (‘ok’)

that is the code you have so far? That more looks like pseudo code then actual code


To have the user enter text, there is the built-in, known as input()

Something like this…

if input("") in list:
    print "ok"

To learn more on how input() works you can check out the docs.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.