Mar-03-2022, 11:23 PM
I would save the dictionary to a json file.
The example below includes a test routine and dictionary display routine which you don't need for your app.
The example below includes a test routine and dictionary display routine which you don't need for your app.
import csv import os import json filename = 'rankedhands.json' def save_rankedhands(): # Make sure cwd same as script os.chdir(os.path.abspath(os.path.dirname(__file__))) fields = ['Rank','Hands'] straightlist = { 1: [['10', 'X'], ['11', 'X'], ['12', 'X'], ['13', 'X'], ['14', 'X']], 2: [['9', 'X'], ['10', 'X'], ['11', 'X'], ['12', 'X'], ['13', 'X']], 3: [['8', 'X'], ['9', 'X'], ['10', 'X'], ['11', 'X'], ['12', 'X']], 4: [['7', 'X'], ['8', 'X'], ['9', 'X'], ['10', 'X'], ['11', 'X']], 5: [['6', 'X'], ['7', 'X'], ['8', 'X'], ['9', 'X'], ['10', 'X']], 6: [['5', 'X'], ['6', 'X'], ['7', 'X'], ['8', 'X'], ['9', 'X']], 7: [['4', 'X'], ['5', 'X'], ['6', 'X'], ['7', 'X'], ['8', 'X']], 8: [['3', 'X'], ['4', 'X'], ['5', 'X'], ['6', 'X'], ['7', 'X']], 9: [['2', 'X'], ['3', 'X'], ['4', 'X'], ['5', 'X'], ['6', 'X']] } with open(filename, 'w') as jfile: json.dump(straightlist, jfile) def display_dict(dictname, level=0): indent = " " * (4 * level) for key, value in dictname.items(): if isinstance(value, dict): print(f'\n{indent}{key}') level += 1 display_dict(value, level) else: print(f'{indent}{key}: {value}') if level > 0: level -= 1 def test_save_rankedhands(): # Save dictionary to json file save_rankedhands() # read json file into newdict and display with open(filename) as jfile: newdict = json.load(jfile) display_dict(newdict) if __name__ == '__main__': test_save_rankedhands()Test results:
Output:1: [['10', 'X'], ['11', 'X'], ['12', 'X'], ['13', 'X'], ['14', 'X']]
2: [['9', 'X'], ['10', 'X'], ['11', 'X'], ['12', 'X'], ['13', 'X']]
3: [['8', 'X'], ['9', 'X'], ['10', 'X'], ['11', 'X'], ['12', 'X']]
4: [['7', 'X'], ['8', 'X'], ['9', 'X'], ['10', 'X'], ['11', 'X']]
5: [['6', 'X'], ['7', 'X'], ['8', 'X'], ['9', 'X'], ['10', 'X']]
6: [['5', 'X'], ['6', 'X'], ['7', 'X'], ['8', 'X'], ['9', 'X']]
7: [['4', 'X'], ['5', 'X'], ['6', 'X'], ['7', 'X'], ['8', 'X']]
8: [['3', 'X'], ['4', 'X'], ['5', 'X'], ['6', 'X'], ['7', 'X']]
9: [['2', 'X'], ['3', 'X'], ['4', 'X'], ['5', 'X'], ['6', 'X']]