""" Week11-1 Notes """

import csv

f = open("icecream.csv", "r")
data = list(csv.reader(f))
print(data)
f.close()

###

import json

f = open("icecream.json", "r")
j = json.load(f)
print(j)
f.close()

###

f = open("chat.txt", "r")
text = f.read()
f.close()

lines = text.split("\n")
result = []
for line in lines:
    start = line.index("From")
    line = line[start + len("From"):]
    end = line.index(":")
    line = line[:end]
    if "(Privately)" in line:
        end = line.index(" to ")
        line = line[:end]
    line = line.strip()
    result.append(line)
print(result)

###

import csv
f = open("icecream.csv", "r")
data = list(csv.reader(f))
f.close()

header = data[0] # isolate header & update it
header.pop(0)
header.append("# Chocolate")

for row in range(1, len(data)): # skip row 0 - header
    data[row].pop(0)
    chocCount = 0
    for col in range(len(data[row])):
        data[row][col] = data[row][col].lower()
        if "chocolate" in data[row][col]:
            chocCount += 1
    data[row].append(chocCount)

print(data)
