Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Created August 7, 2019 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/a8789a7157a5c692a1b76d74d5fa96c1 to your computer and use it in GitHub Desktop.
Save topherPedersen/a8789a7157a5c692a1b76d74d5fa96c1 to your computer and use it in GitHub Desktop.
Sort of Complicated Python Dictionaries
# Playing around with Python Dictionaries
# (planning on using something like this to spit out JSON with Flask)
my_dictionary = {
"foo": 13,
"bar": 18.7,
"baz": "yeet"
}
print(my_dictionary["foo"])
print(my_dictionary["bar"])
print(my_dictionary["baz"])
class Category:
def __init__(self, name, number_of_transactions, amount_spent):
self.name = name
self.number_of_transactions = number_of_transactions
self.amount_spent = amount_spent
list_of_categories = []
first_category = Category("Fast Food", 13, 427.33)
second_category = Category("Restaurants", 1, 54.0)
third_category = Category("Entertainment", 2, 125.0)
list_of_categories.append(first_category)
list_of_categories.append(second_category)
list_of_categories.append(third_category)
more_complicated_dictionary = {
"category": list_of_categories
}
print(more_complicated_dictionary["category"][0].name)
print(more_complicated_dictionary["category"][0].number_of_transactions)
print(more_complicated_dictionary["category"][0].amount_spent)
print(more_complicated_dictionary["category"][1].name)
print(more_complicated_dictionary["category"][1].number_of_transactions)
print(more_complicated_dictionary["category"][1].amount_spent)
print(more_complicated_dictionary["category"][2].name)
print(more_complicated_dictionary["category"][2].number_of_transactions)
print(more_complicated_dictionary["category"][2].amount_spent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment