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

PYTHON!! PLEASE HELP!!! The CSV file is included Example \"info\" file: ID Name

ID: 3823111 • Letter: P

Question

PYTHON!! PLEASE HELP!!! The CSV file is included

Example "info" file: ID Name Type 1" Type 2 Generation Legendary 1, "Bulbasaur", Grass Poison 1, "FALSE" 6, "Charizard "Fire 4, "Charmander Fire FALSE" 169, "Crobat Poison Flying", 2, "FALSE" 146, "Moltres Fire Flying", "TRUE" 643, "Reshiram", Dragon Fire 5,"TRUE" 641, "Tornadus, (Incarnate Form) ","Flying 5 "TRUE" Example "stats" file ID HP "Attack Defense Speed 1,45,49,49,45 4,39,52,43,65 6,78,84,78, 1000 146,90,100, 90,90 149,91,134, 95,80 641,79,115, 70,111 643,100, 120,100,90

Explanation / Answer

# Pastebin link for code: https://pastebin.com/aaebvgqu

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 = ""
for i in range(-1, -1*len(header)+1, -1):
pokemon[header[i]] = entry[i]
if len(entry) == 7:
name = "".join(entry[1:3])
else:
name = entry[1]
info_db[name] = (entry[0], entry[-4], entry[-3], entry[-2], entry[-1])
return info_db

info = read_info_file("info.csv")
print(info['"Bulbasaur"'])
print(info)

File used:

info.csv

"ID","Name","Type 1","Type 2","Generation","Legendary"
1,"Bulbasaur","Grass","Poison",1,"False"
6,"Charizard","Fire","Flying",1,"False"
4,"Charmander","Fire","",1,"Flase"
169,"Corbat","Poison","Flying",2,"False"
146,"Moltres","Fire","Flying",1,"True"
643,"Reshiram","Dragon","Fire",5,"True"
641,"Tornadus, (Incarnate Form)","Flying","",5,"True"

Please rate positively if this solved your question.