accessing elements in dictreader

Solutions on MaxInterview for accessing elements in dictreader by the best coders in the world

showing results for - "accessing elements in dictreader"
Lucas
24 Oct 2019
1import csv
2
3input_file = csv.DictReader(open("people.csv"))
4
5max_age = None
6oldest_person = None
7for row in input_file:
8    age = int(row["age"])
9    if max_age == None or max_age < age:
10        max_age = age
11        oldest_person = row["name"]
12
13if max_age != None:
14    print "The oldest person is %s, who is %d years old." % (oldest_person, max_age)
15else:
16    print "The file does not contain any people."
17
similar questions
queries leading to this page
accessing elements in dictreader