Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Database: a \"database\" of Pokemon can store multiple Pokemon by name. Our data

ID: 3823968 • Letter: D

Question

Database: a "database" of Pokemon can store multiple Pokemon by name. Our database will be a dictionary whose keys are Pokemon names, and whose values are tuples of interesting information about the Pokemon (in the combined final database format shown above). Only Pokemon with stored information and statistics may be present. sample db (1 Grass Poison 45 49, 49, 45, 1, False) Bulbasaur Charmander (4, Fire None 39 52, 43, 65, 1, False) (6, Fire Flying 78 84 78,100, 1, False) Charizard (146, Fire Flying 92,100, 90, 90, 1, True), Moltres "Crobat (169 Poison Flying 85 90, 82,130 2, False) "Tornadus, Incarnate Form (641 Flying None 79,115 70,111, 5, True), Reshiram (643 Dragon s Fire s 100,120,100, 90, 5, True 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 anew 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 ofthe 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'). 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.

Explanation / Answer

def stripQuotes(s):
    if not s:
        return None
    return s[1:-1]

def getBooleanValue(s):
    print(s)
    return stripQuotes(s) == "TRUE"

def read_info_file(filename):
    info_db = {}
    with open(filename, 'r') as f:
        header = f.readline().strip().split(",")
        length = len(header)
        for line in f:
            if not line.strip():
                continue
            entry = line.strip().split(",")
            pokemon = {}
            name = ""
            if len(entry) == 7:
                name = entry[1] + "," + "".join(entry[2:3])
            else:
                name = entry[1]
            info_db[stripQuotes(name)] = (int(entry[0]),
                                          stripQuotes(entry[-4]),
                                          stripQuotes(entry[-3]),
                                          int(entry[-2]),
                                          getBooleanValue(entry[-1]))
    return info_db
   

# code link: https://goo.gl/icWoaW