f = open("dq_unisex_names.csv", "r")
data = f.read()
print(data)

"""
Explanation: 2: Unisex names
3: Read the file into string
Instructions
Use the open() function to return a File object with the parameters:

r for read mode
dq_unisex_names.csv for the file name
Then use the read() method of the File object to read the file into a string. Assign that string to a variable named data.
End of explanation
"""


f = open('dq_unisex_names.csv', 'r')
data = f.read()
data_list = data.split("\n")
print(data_list[:5])

"""
Explanation: 4: Convert the string to a list
Instructions
Use the split() method that strings have to split on the new-line delimiter ("\n") and assign the resulting list to data_list. Then use the print() function to display the first 5 elements in data_list.
Answer
End of explanation
"""


f = open('dq_unisex_names.csv', 'r')
data = f.read()
data_list = data.split('\n')

string_data = []
for data_elm in data_list:
    comma_list = data_elm.split(",")
    string_data.append(comma_list)
    
print(string_data[:5])

"""
Explanation: 5: Convert the list of strings to a list of lists
Instructions
Split each element in data_list on the comma delimiter (,) and append the resulting list to string_data.
To accomplish this:

create an empty list and assign it to string_data
write a for loop that iterates over data_list
within the loop body, run the split() method on each element to return a list (you call that list comma_list)
within the loop body, run the append() method to add each list (comma_list) to string_data.

Finally, use the print() function to display the first 5 elements in string_data.
Answer
End of explanation
"""


numerical_data = []
for str_elm in string_data:
    if len(str_elm) != 2:
        continue
    name = str_elm[0]
    num = str_elm[1]
    lst = [name, num]
    numerical_data.append(lst)
    
# print(numerical_data[:5])

"""
Explanation: 6: Convert numerical values
Instructions
Create a new list of lists called numerical_data where:

the value at index 0 for each list is the unisex name (as a string)

the value at index 1 for each list is the number of people who share that name (as a float)
To accomplish this:


create an empty list and assign to numerical_data

write a for loop that iterates over string_data
in the loop body
retrieve the value at index 0 and assign to a variable
retrieve the value at index 1, convert it to a float, and assign to a variable
create a new list containing these 2 values (in the same order)


use the append() method to add this new list to numerical_data.
Finally, display the first 5 elements in numerical_data.

Answer
End of explanation
"""


