import csv

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

for row in data:
    print(row)
    
###

import json

f2 = open("icecream.json", "r")
obj = json.load(f2)
f2.close()

print(obj)

###

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

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

print(people)

###

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

for row in range(len(data)):
    data[row].pop(0) # remove the ID
    chocCount = 0 # count number of chocolate
    for col in range(len(data[row])):
        # Make all flavors lowercase
        data[row][col] = data[row][col].lower()
        if "chocolate" in data[row][col]:
            chocCount += 1
    # track chocolate count
    if row == 0:
        data[row].append("# chocolate")
    else:
        data[row].append(chocCount)
    # print each row of data after changing it
    print(data[row])
