# variable of type string
name = "James Hunter"
print("name", name, type(name))

print()

# variable of type integer
age = 15
print("age", age, type(age))

# variable of type float
weight = 136
print("weight", weight, type(weight))

print()

# variable of type list (many values in one variable)
langs = ["Python", "JavaScript", "Java", "Bash", "HTML"]
print("langs", langs, type(langs))
print("- langs[0]", langs[0], type(langs[0]))

print()

# variable of type dictionary (a group of keys and values)
person = {
    "name": name,
    "age": age,
    "weight": weight,
    "langs": langs
}
print("person", person, type(person))
print('- person["name"]', person["name"], type(person["name"]))
name James Hunter <class 'str'>

age 15 <class 'int'>
weight 136 <class 'int'>

langs ['Python', 'JavaScript', 'Java', 'Bash', 'HTML'] <class 'list'>
- langs[0] Python <class 'str'>

person {'name': 'James Hunter', 'age': 15, 'weight': 136, 'langs': ['Python', 'JavaScript', 'Java', 'Bash', 'HTML']} <class 'dict'>
- person["name"] James Hunter <class 'str'>
InfoDb = []

# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
    "FirstName": "James",
    "LastName": "Hunter",
    "DOB": "February 23",
    "Residence": "San Diego",
    "Email": "12james15545@gmail.com",
    "Weight": ["136"]
})#InfoDb[0]

InfoDb.append({
    "FirstName": "Nick",
    "LastName": "Hunter",
    "DOB": "June 17th",
    "Residence": "San Diego",
    "Email": "nick@hunter-il.com",
    "Weight": ["155"]
}) # InfoDb[1


print()
print()

# Print the data structure
print(InfoDb)

[{'FirstName': 'James', 'LastName': 'Hunter', 'DOB': 'February 23', 'Residence': 'San Diego', 'Email': '12james15545@gmail.com', 'Weight': ['136']}, {'FirstName': 'Nick', 'LastName': 'Hunter', 'DOB': 'June 17th', 'Residence': 'San Diego', 'Email': 'nick@hunter-il.com', 'Weight': ['155']}]
def print_data(d_rec):
    print(d_rec["FirstName"], d_rec["LastName"])  # using comma puts space between values
    print("\t", "Residence:", d_rec["Residence"]) # \t is a tab indent
    print("\t", "Birth Day:", d_rec["DOB"])
    print("\t", "Socer Number: 12", end="")  # end="" make sure no return occurs


# for loop iterates on length of InfoDb
def for_loop():
    print("For loop output\n")
    for record in InfoDb:
        print_data(record)

for_loop()
For loop output

James Hunter
	 Residence: San Diego
	 Birth Day: February 23
	 Socer Number: 12Nick Hunter
	 Residence: San Diego
	 Birth Day: June 17th
	 Socer Number: 12
#InfoDb is always than i
def while_loop():
    print("While loop output\n")
    i = 0 
    while i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        i += 1
    return

while_loop()
While loop output

James Hunter
	 Residence: San Diego
	 Birth Day: February 23
	 Socer Number: 12Nick Hunter
	 Residence: San Diego
	 Birth Day: June 17th
	 Socer Number: 12
def recursive_loop(i):
    if i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        recursive_loop(i + 1)
    return
    
print("Recursive loop output\n")
recursive_loop(0)
Recursive loop output

James Hunter
	 Residence: San Diego
	 Birth Day: February 23
	 Socer Number: 12Nick Hunter
	 Residence: San Diego
	 Birth Day: June 17th
	 Socer Number: 12

Hacks

  • Add a couple of records to the InfoDb
  • Try to do a for loop with an index
  • Pair Share code somethings creative or unique, with loops and data. Hints...
    • Would it be possible to output data in a reverse order?
    • Are there other methods that can be performed on lists?
    • Could you create new or add to dictionary data set? Could you do it with input?
    • Make a quiz that stores in a List of Dictionaries.
for index in range (len(InfoDb)):
          print_data(InfoDb[index])
James Hunter
	 Residence: San Diego
	 Birth Day: February 23
	 Socer Number: 12Nick Hunter
	 Residence: San Diego
	 Birth Day: June 17th
	 Socer Number: 12
mylist = [1, 2, 3, 4, 5]

mylist.reverse()

mylist
[5, 4, 3, 2, 1]
[5, 4, 3, 2, 1]
a = [10, 20, 30, 40, 50]

len(a)
5
grades = ['A', 'B', 'C', 'D', 'F']

grades.sort(reverse=True)

print(grades)
['F', 'D', 'C', 'B', 'A']
grades = ['A', 'B', 'C', 'D', 'F']

grades.pop(1)
'B'