In python Using the TXBabyNamestxt file Write code to read i
In python: Using the TXBabyNames.txt file.
 Write code to read it into a list.
How many female records are there?
 How many male records are there?
How many female records are there in 1910?
 How many male records are there in 1910?
How many female records are there in 2012?
 How many male records are there in 2012?
What are the total number of babies born in Texas in 2012?
What are the total number of babies born in Texas with your name since 1910?
What are the total number of babies born in Texas with your name between 1910 and 1960?
What name was the most popular (had the highest count in one year) for males?
 What name was the most popular (had the highest count in one year) for females?
What was the name for the males, and for the females?
What year was the name for males? for females?
In what year was your name the most popular (had the highest count)?
 Example name: Paul
Write all this information out to a file.
Link to the TXBabyNames.txt file: https://www.dropbox.com/s/k3f04kklpik62lm/TXBabyNames.txt?dl=0
Solution
#funciton to find out the most occured element of a given list
 def most_common(lst):
 return max(set(lst), key=lst.count)
   
 #please enter your name here
 younName = \"Mary\"  
 #opening the text file in reading mode
 a = open(\"in.txt\",\"r\")
 #reading all the lines of file at once into b
 b = a.readlines()
 #initializing the required variables
 TotalMale = 0
 TotalFemale = 0
 Female1910 = 0
 Male1910 = 0
 Female2012 = 0
 Male2012 = 0
 texas2012 = 0
 texasName1910 = 0
 texasName1910and1960 = 0
 fNames = []
 mNames = []
for i in b:
    l = i.split(\",\")
    city = l[0]
    gen = l[1]
    year = int(l[2])
    name = l[3]
    if(gen == \'F\'):
        TotalFemale += 1
        fNames.append(name)
        if(year == 1910):
            Female1910 += 1
        elif(year == 2012):
            Female2012 += 1  
        else:
            None
    else:
        mNames.append(name)
        TotalMale += 1
        if(year == 1910):
            Male1910 += 1
        elif(year == 2012):
            Male2012 += 1  
        else:
            None
    #born in texas in 2012
    if(city == \'TX\' and year == 2012):  
        texas2012 += 1
   #total number of babies born in Texas with your name since 1910  
    if(city == \'TX\' and year > 1910 and name == younName):
        texasName1910 += 1
   #total number of babies born in Texas with your name between 1910 and 1960
    if(city == \'TX\' and 1910 < year < 1960 and name == younName):
        texasName1910and1960 += 1
 a.close()
out = open(\"out.txt\",\"a\")
 out.write(str(TotalMale))
 out.write(\"How many male records are there? %d \ \"%TotalMale)
 out.write(\"How many female records are there? %d \ \"%TotalFemale)
 out.write(\"How many female records are there in 1910? %d \ \"%Female1910)
 out.write(\"How many male records are there in 1910? %d \ \"%Male1910)
 out.write(\"How many female records are there in 2012? %d \ \"%Female2012)
 out.write(\"How many male records are there in 2012? %d \ \"%Male2012)
 out.write(\"What are the total number of babies born in Texas in 2012? %d \ \"%texas2012)
 out.write(\"What are the total number of babies born in Texas with your name since 1910? %d \ \"%texasName1910)  
 out.write(\"What are the total number of babies born in Texas with your name between 1910 and 1960? %d \ \"%texasName1910and1960)
 out.write(\"What name was the most popular (had the highest count in one year) for males? %d \ \"%most_common(fNames))
 out.write\"What name was the most popular (had the highest count in one year) for females? %d\ \"%most_common(mNames))
 out.close


