# Convert output copied from nobelprize.org "create list" into TSV form # Output looks like: #1998, The Prize in Economic Sciences #Amartya Sen #BORN: 1933-11-03 # This line might be missing from __future__ import print_function def main(): print("Winner\tName\tAward Year\tBirth Year") with open("nobel.list") as f: line = f.readline() while True: if not line: break awardYear = getAwardYear(line) winner, shortName = getWinner(f.readline()) line = f.readline() if not line.startswith("BORN:"): continue birthYear = getBirthYear(line) print("%s\t%s\t%s\t%s" % (winner, shortName, awardYear, birthYear)) line = f.readline() def getAwardYear(line): return line.split(',')[0].strip() def getWinner(line): winner = line.strip() return winner, winner.split()[-1].strip() def getBirthYear(line): return line.strip().split()[-1].split('-')[0] if __name__ == "__main__": main()