#100DaysOfCode Day 9
๐ธ I CREATED MY OWN SECRET AUCTION APP! ๐ธ
CLICK HERE and press "Run" to try it out.
Yesterday I learned how to use the dictionary datatype and nesting them in lists. Now I can work with some complex data in a structured manner. Creating the secret auction was so awesome because it was so simple!
Lessons
- Language switching is hard!
- You can use this site to visualise your codes execution step by step, using this site.
TO THE CODE!!!
# Dictionaries
#{Key:Value}
programming_dictionary = {
"Bug": "An error in a program that prevents the program from running as expected.",
"Function": "A piece of code that you can easily call over and over again.",
"Loop": "The action of doing something over and over again."
}
# Access it by the key, this can also be an int
print(programming_dictionary["Bug"])
# Adding Values
programming_dictionary[123]: "Test int key"
print(programming_dictionary)
# Creating an empty dictionary
empty_dictionary = {}
# Wipe an existing dictionary
programming_dictionary = {}
print(programming_dictionary)
# Edit Values
programming_dictionary[123] = "EDITED: Test int key"
print(programming_dictionary)
#Looping through a dictionary
for item in programming_dictionary:
print(item)
# OUTPUT:
# Bug
# Function
# Loop
# 123
# Use this to get the key and value:
for key in programming_dictionary:
print(key)
print(programming_dictionary[key])
# Nesting
# Dictionary
capitals = {
"France": "Paris",
"Germany": "Berlin"
}
# Nesting a List in a dictionary
travel_log = {
"France": {"cities_visited": ["Paris", "Lille", "Dijon"], "total_visits": 12},
"Germany": {"cities_visited": ["Berlin", "Hamburg", "Stuttgart"], "total_visits": 6}
}
# Nesting a dictionary in a list
travel_log = [
{
"country": "France",
"cities_visited": ["Paris", "Lille", "Dijon"],
"total_visits": 12
},
{
"country": "Germany",
"cities_visited": ["Berlin", "Hamburg", "Stuttgart"],
"total_visits": 6
}
]
The daily grind (working and studying) is tough, but I keep my goals in mind and push forward!