InfoDb

InfoDb is a dictionary inside of a list. Here is an example code using InfoDb:

InfoDb = []

# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
    "FirstName": "John",
    "LastName": "Mortensen",
    "DOB": "October 21",
    "Residence": "San Diego",
    "Email": "jmortensen@powayusd.com",
    "Owns_Cars": ["2015-Fusion", "2011-Ranger", "2003-Excursion", "1997-F350", "1969-Cadillac"]
})

# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "Sunny",
    "LastName": "Naidu",
    "DOB": "August 2",
    "Residence": "Temecula",
    "Email": "snaidu@powayusd.com",
    "Owns_Cars": ["4Runner"]
})

InfoDb.append({
    "FirstName": "Ryan",
    "LastName": "Hakimipour",
    "DOB": "June 15",
    "Residence": "San Diego",
    "Email": "hakimipourryan@gmail.com",
    "Owns_Cars": ["None"]
})

InfoDb.append({
    "FirstName": "Soham",
    "LastName": "Kamat",
    "DOB": "March 9",
    "Residence": "San Diego",
    "Email": "sohamk10039@stu.powayusd.com",
    "Owns_Cars": ["None"]
})
# Print the data structure
print(InfoDb)
[{'FirstName': 'John', 'LastName': 'Mortensen', 'DOB': 'October 21', 'Residence': 'San Diego', 'Email': 'jmortensen@powayusd.com', 'Owns_Cars': ['2015-Fusion', '2011-Ranger', '2003-Excursion', '1997-F350', '1969-Cadillac']}, {'FirstName': 'Sunny', 'LastName': 'Naidu', 'DOB': 'August 2', 'Residence': 'Temecula', 'Email': 'snaidu@powayusd.com', 'Owns_Cars': ['4Runner']}, {'FirstName': 'Ryan', 'LastName': 'Hakimipour', 'DOB': 'June 15', 'Residence': 'San Diego', 'Email': 'hakimipourryan@gmail.com', 'Owns_Cars': ['None']}, {'FirstName': 'Soham', 'LastName': 'Kamat', 'DOB': 'March 9', 'Residence': 'San Diego', 'Email': 'sohamk10039@stu.powayusd.com', 'Owns_Cars': ['None']}]

For Loops and Index

Using for loops and iterating through using index in python. Here is a simple example:

Food = ["Burger", "Hot Dog", "Fries", "Pizza", "Goldfish", "Donut", "M&M", "Beef Kebab", "Chicken Kebab", "Burrito", "Tacos", "Chicken Sandwich"]
for i in Food:
    print(i)
Burger
Hot Dog
Fries
Pizza
Goldfish
Donut
M&M
Beef Kebab
Chicken Kebab
Burrito
Tacos
Chicken Sandwich

Outputting in Reverse Order

It is possible to output data in a reverse order. Here is an example using a palindrome:

def is_palindrome(prompt):
    print(prompt[::-1])
    print(prompt)
    return prompt[::-1] == prompt

word = input("Enter a word: ")
if is_palindrome(word.lower()) is True:
    print("{0} is a palindrome!".format(word))
else:
    print("The provided word is not a palindrome.")
olleh
hello
The provided word is not a palindrome.

Other list methods

Lists can have a variety of methods performed on them. A couple being .append() or while loop. Here is an example using .append() and .lower() with a for loop:

Dangerous_Animals = ["Box Jellyfish", "African CAPE BuFfalo", "BLAck MambA", "Blue-RINGED octopus"]
Dangerous_Animals.append("Cone SnAIl")
for i in range(len(Dangerous_Animals)):
    Dangerous_Animals[i] = Dangerous_Animals[i].lower()
print(Dangerous_Animals)
['box jellyfish', 'african cape buffalo', 'black mamba', 'blue-ringed octopus', 'cone snail']

Adding to a Dictionary

You can also add or create new keys and values to a dictionary data set. This can also be done with input. Here is an example:

My_Dict = {
    "Absence": "The lack or unavailability of something or someone.",
    "Approval": "Having a positive opinion of something or someone.",
    "Answer": "The response or receipt to a phone call, question, or letter.",
    "Attention": "Noticing or recognizing something of interest.",
    "Amount": "A mass or a collection of something.",
    "Borrow": "To take something with the intention of returning it after a period of time.",
    "Baffle": "An event or thing that is a mystery and confuses.",
    "Ban": "An act that is prohibited by social pressure or law.",
    "Cars": "Four-wheeled vehicles used for traveling.",
}
print(My_Dict)
My_Dict["Care"] = "extra responsibility and attention." #Added new key and value into dictionary
print(My_Dict)
My_Dict["Chip"] = input() # Added new value with input
print(My_Dict)
{'Absence': 'The lack or unavailability of something or someone.', 'Approval': 'Having a positive opinion of something or someone.', 'Answer': 'The response or receipt to a phone call, question, or letter.', 'Attention': 'Noticing or recognizing something of interest.', 'Amount': 'A mass or a collection of something.', 'Borrow': 'To take something with the intention of returning it after a period of time.', 'Baffle': 'An event or thing that is a mystery and confuses.', 'Ban': 'An act that is prohibited by social pressure or law.', 'Cars': 'Four-wheeled vehicles used for traveling.'}
{'Absence': 'The lack or unavailability of something or someone.', 'Approval': 'Having a positive opinion of something or someone.', 'Answer': 'The response or receipt to a phone call, question, or letter.', 'Attention': 'Noticing or recognizing something of interest.', 'Amount': 'A mass or a collection of something.', 'Borrow': 'To take something with the intention of returning it after a period of time.', 'Baffle': 'An event or thing that is a mystery and confuses.', 'Ban': 'An act that is prohibited by social pressure or law.', 'Cars': 'Four-wheeled vehicles used for traveling.', 'Care': 'extra responsibility and attention.'}
{'Absence': 'The lack or unavailability of something or someone.', 'Approval': 'Having a positive opinion of something or someone.', 'Answer': 'The response or receipt to a phone call, question, or letter.', 'Attention': 'Noticing or recognizing something of interest.', 'Amount': 'A mass or a collection of something.', 'Borrow': 'To take something with the intention of returning it after a period of time.', 'Baffle': 'An event or thing that is a mystery and confuses.', 'Ban': 'An act that is prohibited by social pressure or law.', 'Cars': 'Four-wheeled vehicles used for traveling.', 'Care': 'extra responsibility and attention.', 'Chip': 'Absence'}

Python Quiz

Making a quiz that uses a list of dictionaries (InfoDb):

def Python_Quiz(prompt):
    global word
    print ("Question: " + prompt)
    word = input()
    return word

questions_number = 5
correct_answer = 0

print("Hello, you will be asked " + str(questions_number) + " short questions")

My_Quiz = [{
    "What is the answer to this math problem: What does 45x7=": "315",
    "What is the most popular religion in the world?": "Christianity",
    "What is the capital of the U.S?": "Washington D.C.",
    "How many kg is in 5g?": "0.005 kg",
    "How many mm are in 1 km?": "1000000 mm",
}]
# My_Quiz.append({
#     "What is the answer to this math problem: What does 45x7=": "315",
#     "What is the most popular religion in the world?": "Christianity",
#     "What is the capital of the U.S?": "Washington D.C.",
#     "How many kg is in 5g?": "0.005 kg",
#     "How many mm are in 1 km?": "1000000 mm",
# })

for dict in My_Quiz:
    for questions, answers in dict.items():
        Python_Quiz(questions)
        if word == answers:
            print("Answer is correct")
            correct_answer += 1
        else:
            print("Answer is incorrect")

print("You scored " + str(correct_answer) + "/" + str(questions_number))
Hello, you will be asked 5 short questions
Question: What is the answer to this math problem: What does 45x7=
Answer is correct
Question: What is the most popular religion in the world?
Answer is correct
Question: What is the capital of the U.S?
Answer is correct
Question: How many kg is in 5g?
Answer is correct
Question: How many mm are in 1 km?
Answer is incorrect
You scored 4/5