In the cell below, the code creates a "dictionary" where all the data is stored. I decided to define certain things about me to show my understanding of data structures. tesst

InfoDb = []

# Creating keys and values for the data structure
InfoDb.append({
    "FirstName": "Trent",
    "LastName": "Cardall",
    "Class": "APCSP",
    "Date of Birth": "March 9, 2005",
    "Place of Birth": "Scottsdale, AZ",
    "Hobbies": ["Playing music", "Surfing", "Playing Lacrosse"] # [] makes ordered list
    
})

print (InfoDb)
[{'FirstName': 'Trent', 'LastName': 'Cardall', 'Class': 'APCSP', 'Date of Birth': 'March 9, 2005', 'Place of Birth': 'Scottsdale, AZ', 'Hobbies': ['Playing music', 'Surfing', 'Playing Lacrosse']}]

The data structure was printed which shows proof that it works. However, it is not exactly easy for the average person to read. By using other functions we can format the list to make the output more organized. There are multiple ways to pull data out of the structure, but all of them will produce the same output.

For loop

Pulls records one by one out of data structure until there is nothing left

def print_data(d_rec):
    print(d_rec["FirstName"], d_rec["LastName"])
    print("\t", "-Class:", d_rec["Class"])
    print("\t", "-Date of Birth:", d_rec["Date of Birth"])
    print("\t", "-Place of Birth:", d_rec["Place of Birth"])
    print("\t", "-Hobbies:", end="")
    print(", ".join(d_rec["Hobbies"]))


def for_loop():
    print("A little about myself:")
    for record in InfoDb:
        print_data(record)


for_loop() # activating function
A little about myself:
Trent Cardall
	 -Class: APCSP
	 -Date of Birth: March 9, 2005
	 -Place of Birth: Scottsdale, AZ
	 -Hobbies:Playing music, Surfing, Playing Lacrosse

While loop

Counts through the items in the list until record is passed.

def while_loop():
    print("A little about myself:")
    i = 0
    while i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        i +=1
    return

while_loop()
A little about myself:
Trent Cardall
	 -Class: APCSP
	 -Date of Birth: March 9, 2005
	 -Place of Birth: Scottsdale, AZ
	 -Hobbies:Playing music, Surfing, Playing Lacrosse

Recursion

Using a function defined as recursive_loop(i), each time data is pulled out it will add a number to i to move on to the next item in the list. Eventually i < len(InfoDb) will be false, and the loop will end

def recursive_loop(i):
    if i < len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        recursive_loop(i + 1)

print ("A little about myself:")
recursive_loop(0)
A little about myself:
Trent Cardall
	 -Class: APCSP
	 -Date of Birth: March 9, 2005
	 -Place of Birth: Scottsdale, AZ
	 -Hobbies:Playing music, Surfing, Playing Lacrosse

Reverse Order

One of the hacks is to attempt to display the list in reverse order. The first idea that came to mind and seemed easiest was to change the recursive loop so that it subtracts each time, and start it at the highest number of the list.

def reverse_order(i):
    if i <= len(InfoDb):
        record = InfoDb[i]
        print_data(record)
        reverse_order(i - 1)

print("Reverse order"+"\n")
print("A little about myself:")
reverse_order(6)
Reverse order

A little about myself:

That didn't seem to work, and I couldn't think of any other ideas, so I tried a quick google search, and attempted new methods

InfoDb.reverse()
print(InfoDb)
[{'FirstName': 'Trent', 'LastName': 'Cardall', 'Class': 'APCSP', 'Date of Birth': 'March 9, 2005', 'Place of Birth': 'Scottsdale, AZ', 'Hobbies': ['Playing music', 'Surfing', 'Playing Lacrosse']}]

That didn't seem to do anything either. I am not quite sure how to reverse this particular list, so I am going to attempt making a simpler list and reversing it.

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "v", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
print("Normal order:", alphabet, "\n")

alphabet.reverse()
print("Reverse order:", alphabet)
Normal order: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'v', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] 

Reverse order: ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'v', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']

That worked! Unfortunately I was not able to find a way to reverse the previous, more complicated list I made but I did reverse a list.

Turning list into a table:

A little about myself: |Key|Value| |---|--- | |Class|APCSP| |Date of Birth|March 9, 2005| |Place of Birth|Scottsdale, AZ| |Hobbies|Playing music, Surfing, Playing Lacrosse|