Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions