You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#parse a file and return the lines which have number
#Input
#ls -la
#4
#lo poll
#78
#Output
#['4','78']
defparser(filename):
lines= []
num_list= []
fh=None
try:
fh=open(filename, encoding="utf8")
lines=fh.readlines()
num_lines=len(lines)
#print(num_lines) #-> checking how many lines get printed, remove # before print
i=0
whilei<num_lines:
line=lines[i].strip()
#print (type(line)) #-> checking each line type() that was read in lines variable above,whether it's an integer or string remove # before print, ypu might notice even a number from a file is read as string
# this means we cannot apply a logic where we identify if in a given line there is a number or letter, we might need to use regex
ifline.isdigit():
print ('Hurray! Found a number')
#print(line) # -> each line that was read in lines variable above, remove # before print
num_list.append(line)
else:
pass
#print(line) # -> each line that was read in lines variable above, remove # before print