I have a list 'a',where I need to print all the matching letters of the list with the line of a text file 'hello.txt'.But it only prints the first word from the list and line instead of all the list and lines
a=['comp','graphics','card','part']
with open('hello.txt', 'r') as f:
for key in a:
for line in f:
if key in line:
print line, key
It results as:
comp and python
comp
Desired output:
comp and python
comp
graphics and pixel
graphics
micro sd card
card
python part
part
Please help me to get desires output.Answers willbe appreciated!