<jupyter_start><jupyter_text>Open the fileMy BU ID is U64501194Therefore, I am dealing with the silver medals<jupyter_code># -*- coding: utf-8 -*-
"""
Created on Mon Nov  5 14:37:29 2018

@author: epinsky
this scripts reads your ticker file (e.g. MSFT.csv) and
constructs a list of lines
"""
import os

ticker='Country_Medals'
input_dir = os.getcwd()
ticker_file = os.path.join(input_dir, ticker + '.csv')

try:   
    with open(ticker_file) as f:
        lines = f.read().splitlines()
    print('opened file for ticker: ', ticker)
    """    your code for assignment 1 goes here
    """
    
except Exception as e:
    print(e)
    print('failed to read stock data for ticker: ', ticker)

lines[0:5]<jupyter_output><empty_output><jupyter_text>Extract the data<jupyter_code># Class a data type (year, countryName, silverMetal)
class DataNode:
    def __init__(self, year, countryName, silver):
        self.year = year
        self.countryName = countryName
        self.silver = silver
    def show(self):
        print("{:5}  {:15}  {:3}".format(self.year, self.countryName, self.silver))
# Split the raw data into list
table = []
for line in lines:
    temp = line.split(',')
    table.append(temp)
  
# Extract the Data
extractData = []
for row in table:
    y = row[0]
    cn = row[2]
    s = row[6]
    dataNode = DataNode(y, cn, s)
    extractData.append(dataNode)

# Remove the title from the extractData
extractData = extractData[1:]
# Show the first 5 row of the extracted data
for i in range(5):
    extractData[i].show()<jupyter_output>1932   United States    32 
1932   Italy            12 
1932   France           5  
1932   Sweden           5  
1932   Japan            7<jupyter_text>Analysis<jupyter_code># How many entries
entries = len(extractData)
print("we have {} entries of data and 1 row of title".format(entries))
# Count the average medals of each country
# Sort the list with the key 'countryName'
sortData = sorted(extractData, key= lambda x:x.countryName)
# Show first 5 data
for node in sortData:
    node.show()
# Extract the country from data
temp = []
for node in sortData:
    c = node.countryName
    temp.append(c)


# Processing the data into the form (countryname, list(a series of medal wins)
countrySet = sorted(set(temp))
medalList = [[] for i in range(len(countrySet))]

for node in sortData:
    n = node.countryName
    s = node.silver
    index = countrySet.index(n)
    medalList[index].append(s)
    
countryMedalData = list(zip(countrySet, medalList))
for data in countryMedalData[0:5]:
    print(data)<jupyter_output>('Afghanistan', ['0', '0'])
('Algeria', ['0', '2', '0', '1', '1', '0', '0'])
('Argentina', ['1', '3', '3', '1', '0', '1', '1', '1', '1', '1', '0', '0', '2', '2', '0', '1', '1', '2', '3', '2'])
('Armenia', ['2', '3', '1', '1', '0', '1'])
('Australasia', ['2', '2'])
{'fraction_non_alphanumeric': 0.1474019088016967, 'fraction_numerical': 0.03570166136443973, 'mean_word_length': 3.5425361155698236, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '276533', 'license': 'MIT', 'n_tokens_mistral': 1032, 'n_tokens_neox': 987, 'n_words': 315, 'path': 'Assignment_1/Part_1_medals/.ipynb_checkpoints/Olympic Medal-checkpoint.ipynb', 'repo_name': 'KyleLeePiupiupiu/CS677_Assignment', 'size': '2829'}