File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -159,3 +159,25 @@ def super_reduced_string(s):
159
159
else :
160
160
return 'Empty String'
161
161
print (super_reduced_string ('aaabccddd' ) )
162
+
163
+
164
+ ###########################################################################################################################
165
+ #we want to write a program that takes a list of filenames as arguments and to print only the line which has a particular substring,
166
+ like grep command in unix .
167
+ def readfiles (filenames ):
168
+ for f in filenames :
169
+ with open (f ) as fr :
170
+ for line in open (fr ):
171
+ yield line
172
+
173
+ def grep (pattern , lines ):
174
+ return (line for line in lines if pattern in line )
175
+
176
+ def printlines (lines ):
177
+ for line in lines :
178
+ print (line )
179
+
180
+ def main (pattern , filenames ):
181
+ lines = readfiles (filenames )
182
+ lines = grep (pattern , lines )
183
+ printlines (lines )
You can’t perform that action at this time.
0 commit comments