Q:

Python program to extract keywords from the list

0

We have a list of sentences, and we need to find all the keywords present in the list and print them all.

Example:

List:
["include help is" , "great platform for programmers"]

Keywords:
["is" , "for"]

We have a list of sentences and we need to find all keywords present in it. We will loop through the list and check each letter if it is a keyword using the isKeyword() method from the keyword module. Then store these keywords in a list and print it.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to extract keyword from the list

# Python Program to extract keywords from the list...

# Import iskeyword method
from keyword import iskeyword 

# Initializing list of sentences...
listOfSentence = ["include help is", "great platform for programmers"]

# Printing original list
print("List of sentences = ", end = " ")
print(listOfSentence)

keywordList = [] 
# Iterating using loop and checking for Keywords...
for sentence in listOfSentence:
    for words in sentence.split():
    	if iskeyword(words):
		    keywordList.append(words)

# Print keyword list...
print("Keywords present in List : ", end = " " )
print(keywordList)

Output:

List of sentences =  ['include help is', 'great platform for programmers']
Keywords present in List :  ['is', 'for']

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now