Nov-17-2020, 11:34 PM
python comprehensions can be confusing at first if you're not used to them. They're a very compact way to express a collection of info.
You don't have to use them. You could just write it as a regular loop.
Explicit loop:
You don't have to use them. You could just write it as a regular loop.
Explicit loop:
tof = ['try','two'] with open('C:/02/file1.txt', 'r') as th_th : for line in th_th: for word in tof: if word in line: print(line) breakComprehension:
tof = ['try','two'] with open('C:/02/file1.txt', 'r') as th_th : print([line for line in th_th if any(word in line for word in tof)])