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 = float(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
"""


# The last value is ~100 people
numerical_data[len(numerical_data)-1]

thousand_or_greater = []
for num in numerical_data:
    if num[1] >= 1000:
        thousand_or_greater.append(num[0])
        
print(thousand_or_greater[:10])

"""
Explanation: 7: Filter the list
Instructions
Create a new list of strings called thousand_or_greater that contains just the names that at least a thousand people share.
To accomplish this:

create an empty list and assign to thousand_or_greater
write a for loop that iterates over numerical_data
in the loop body, use an if statement to determine if the value at index 1 for that element (a list) is greater than or equal to 1000
if the value is larger than or equal to 1000, use the append() method to add it to thousand_or_greater

Finally, display the first 10 elements in thousand_or_greater.
Answer
End of explanation
"""


