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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started