Goal: Print out the values of a dictionary via a for loop
Here is a recreated version of the code as reference (not the actual code, works just the same):
import networkx as nx
random_dictionary = {
"name": "DAG",
"children": "None",
"father": "None",
"mother": "None",
"spouse": "None",
}
serializable_format = random_dictionary
for n in serializable_format:
print("[+] node: " + n + ", edge: " + str(serializable_format[n]['pre_transactions']))
for x in serializable_format[n]['pre_transactions']:
ledger.add_edge(n, x)
When I execute it, I am constantly met with the following error...
TypeError: string index indices must be integers or slices, not str
I can not insert an integer in the [n] section, as that would give me the following error
KeyError: (insert any number here)
So how do I go about making a for loop which gets the content from the dictionary without encountering any errors?