Question: I have this python code that needs to strip and remove all numbers/characters around the index. there's something im doing wrong and i cannot understand
I have this python code that needs to strip and remove all numbers/characters around the index. there's something im doing wrong and i cannot understand what. this is my code:
def extract_idnumbers(file): ids = [] file = "cards.txt" f = open(file) for i in file: left = i.index('4') #get index of left parenthesis right = i.index('?') #get index of right parenthesis id = i[left+1 : right] #extract the characters after left upto right (excluded) ids.append(id.strip()) file.close() return ids f.close()
ids = extract_idnumbers(f) print(ids)
this is my text file. after it strips it should only print '900702736":
;6035095514677460? ;34900702736?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
