Esempio n. 1
0
def copyEmail(inFile,outFile):
    """
    Copies the value of the emails from the input csv file and writes them to the output csv file.
    """
    facultyLst=a.getFacultyList(inFile)
    emails = [staff['email'] for staff in facultyLst]
    f_out=open(outFile,'w')
    for email in emails:
        f_out.write(email+'\n')
    f_out.close()
Esempio n. 2
0
def regex(inputFile):
    """
    Takes values of emails from csv input file and makes a list of their domains.
    """
    facultyLst=a.getFacultyList(inputFile)
    emails = [staff['email'] for staff in facultyLst]
    domains=[]
    for email in emails:
        if email.split('@')[1] not in domains:
            domains.append(email.split('@')[1])
    print 'Number of different domains:',len(domains)
    print 'List:',domains
Esempio n. 3
0
def faculty_dictionary(inputFile,dictKey,stortValue=0):
    '''
    Returns a dictionary with values being a list of degree,title,email.
    The function will sort the values then print the top three on the sort
    '''
    facultyLst=a.getFacultyList(inputFile)
    faculty_dict={ eval(dictKey):[] for staff in facultyLst}
    for staff in facultyLst:
        faculty_dict[eval(dictKey)].append(
            [staff['degree'].replace(' ','',1),
             staff['title'].replace('is','of').split(' of')[0],
             staff['email']])
    facultyLst=sorted(faculty_dict.items(), key=lambda x: x[0][stortValue])
    for i in xrange(3):
        print facultyLst[i]
    return faculty_dict
Esempio n. 4
0
# goals scored for and against each team in that season (so Arsenal scored 79 goals 
# against opponents, and had 36 goals scored against them). Write a program to read the file, 
# then print the name of the team with the smallest difference in ‘for’ and ‘against’ goals.


#import csv

  #def read_data(data):
   # COMPLETE THIS FUNCTION

  #def get_min_score_difference(self, parsed_data):
    # COMPLETE THIS FUNCTION

  #def get_team(self, index_value, parsed_data):
    # COMPLETE THIS FUNCTION

########################################################################################
# I really didn't follow the above outline. I was not sure what was going on.
# The self as functions inputs are for a class from my understanding but no class is stated.
# So I just completed the goal of the problem of:
#
# "Write a program to read the file, 
# then print the name of the team with the smallest difference in ‘for’ and ‘against’ goals."
#
# I already had to code the read data part for part 05b_advanced_python so I just reused that
# helper code file. Afterwards just sorted and printed the top results team name. 
########################################################################################
import advanced_python as a
a.getFacultyList('football.csv')
print sorted(data,key= lambda d: abs(int(d['Goals'])-int(d['Goals Allowed'])))[0]['Team']