Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If Sage is the only program that needs to read the data, you can use the "save" and "load" commands:

sage: square_sum = dict(((a,b),a^2+b^2) for a,b in CartesianProduct([1..5],[1..5]))
sage: square_sum 
{(1, 3): 10, (5, 4): 41, (2, 1): 5, (5, 1): 26, (2, 5): 29, (1, 2): 5, (3, 3): 18, (4, 4): 32, (1, 5): 26, (2, 2): 8, (5, 3): 34, (4, 1): 17, (1, 1): 2, (3, 2): 13, (4, 5): 41, (5, 5): 50, (1, 4): 17, (2, 3): 13, (4, 2): 20, (3, 5): 34, (3, 4): 25, (3, 1): 10, (4, 3): 25, (5, 2): 29, (2, 4): 20}
sage: save(square_sum, "ssum")
sage: s2 = load("ssum")
sage: s2
{(1, 3): 10, (3, 2): 13, (2, 1): 5, (5, 1): 26, (2, 5): 29, (1, 2): 5, (3, 3): 18, (4, 4): 32, (1, 5): 26, (2, 2): 8, (3, 5): 34, (4, 1): 17, (1, 1): 2, (5, 4): 41, (4, 5): 41, (1, 4): 17, (2, 3): 13, (4, 2): 20, (5, 5): 50, (5, 3): 34, (5, 2): 29, (3, 1): 10, (4, 3): 25, (3, 4): 25, (2, 4): 20}
sage: s2 == square_sum
True

(Remember that dictionaries don't have an order, so the fact that the keys show up differently in s2 than in the original square_sum doesn't matter.)