Created
September 6, 2021 19:16
-
-
Save EngEryx/ad15a8b8cf174f7f7789d72cff490b8b to your computer and use it in GitHub Desktop.
Dictionary as my naive graph db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a sample Python script. | |
# Eng Eryx | |
my_graph_db = dict({'n': 0}) | |
def insert(item): | |
n = my_graph_db['n'] + 1 | |
item['id'] = n | |
my_graph_db[n] = item | |
my_graph_db['n'] = n | |
def delete(item=None, key=0): | |
if item is not None: | |
my_graph_db.pop(item['id']) | |
if key != 0: | |
my_graph_db.pop(key) | |
def test_run(): | |
# Add some transactions to my dict | |
insert({'id': 0, 'amount': 1000, 'type': 'debit', 'date': '20210906T21:54:00'}) | |
trans_2 = {'id': 0, 'amount': 1000, 'type': 'debit', 'date': '20210906T21:54:00'} | |
insert(trans_2) | |
insert({'id': 0, 'amount': 1000, 'type': 'debit', 'date': '20210906T21:54:00'}) | |
insert({'id': 0, 'amount': 1000, 'type': 'debit', 'date': '20210906T21:54:00'}) | |
print(my_graph_db) | |
# Press the green button in the gutter to run the script. | |
if __name__ == '__main__': | |
test_run() | |
# See PyCharm help at https://www.jetbrains.com/help/pycharm/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment