Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with these functions! I worked on this code so far, but it's working any help? thank you def read_info_file(filename): d1={} info=[] with open(filename,r) as

Help with these functions!

image text in transcribed

I worked on this code so far, but it's working any help? thank you

def read_info_file(filename): d1={} info=[] with open(filename,"r") as f: f.readline()#reading headers for line in f: line=line.replace('"','') count=line.count(",") if(count==6): str=line.split(",") str[1]=str[1]+","+str[2] info=[a for a in str if a.count(",")==0] else: info=line.split(",") d1[info[1]]=(int(info[0]),info[2],info[3],int(info[4]),info[5]=="True")

return d1

def read_stats_file(filename): d2={} stats=[] with open(filename,"r") as f: f.readline()#reading headers for line in f: stats=line.split(",") d2[int(stats[0])]=(int(stats[1]),int(stats[2]),int(stats[3]),int(stats[4])) return d2

def combine_databases(info_db,stats_db): finaldict={} for names in info_db: for id in stats_db: a,b,c,d,e=info_db[names] f,g,h,i=stats_db[id] if(a==id): finaldict[names]=(a,b,c,f,g,h,i,d,e) break

return finaldict

Files need for the project- https://1drv.ms/f/s!Ao67XhHyOEGibbrG8-EI9OxQDPc

tester file is given in the folder above -> when you run the file it should be like follows

python tester5p.py projectfilename.py

Functions You must implement the following functions. Examples can be found later in this document (under "Examples"). Methods NEVER modify the given database, but some functions create a new database. read info file(filename): This is only one of two functions that deals with reading a file. It accepts the file name as a string, assume it is a CSV file in the format described above for an "info" file. The function needs to open the file, read all the described pokemon, and create a dictionary of pokemon in the INFO FORMAT. It returns the dictionary it creates. Note: the first line of the file is always a "header" line which does not corresponds to any pokemon; the last line of the file always ends with a newline ('Nn') Special case: Name field in the input file might contain one comma as part of the string, for example, "Tornadus, (Incarnate Form)". You can assume the name can have at most one comma and all other fields do not have any comma. read stats file(filename): This is the other one of two functions that needs to deal with reading a file. It accepts the file name as a string, assume it is a CSV file in the format described above for a "stats" file. The function needs to open the file, read all the described pokemon, and create a dictionary of pokemon in the STATSFORMAT It returns the dictionary it creates. Note: the first line of the file is always a "header" line which does not corresponds to any pokemon, the last line of the file always ends with a newline ('Vn') combine databases (info db, stats db): This function takes two dictionaries (one in INFO FORMAT and one in STAT FORMAT) and combines them into a final dictionary "database" (described in the previous section). Items from one dictionary that do not appear in the other should be discarded. It returns the combined dictionary. NOTE: All functions below will be expecting a full database, not an info or stats dictionary

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions