In [3]:
students = [
{ 'Name':'bob','GPA':3.4, 'Ischool' : True },
{ 'Name':'sue','GPA':2.8, 'Ischool' : True },
{ 'Name':'kent','GPA':4.0, 'Ischool' : False }
]
print(students)
In [4]:
type(students)
Out[4]:
In [9]:
students[-1]
Out[9]:
In [5]:
type(students[-1])
Out[5]:
In [6]:
print(students[-1])
In [7]:
# print names and GPA's of just ischool students:
for student in students: # list
if student['Ischool']: # == True is not necessary
print(student['Name'], student['GPA'])
In [7]:
students = [
{"Name": "bob", "age": 18, "grades": [70, 80, 30]},
{"Name": "Tom", "age": 20, "grades": [70, 80, 30]},
{"Name": "Jerry", "age": 19, "grades": [70, 80, 30]}
]
for student in students:
print("Grades for: " + student["Name"])
for grade in student["grades"]:
print(grade)
In [ ]: