1 | initial version |
I would suggest to use Python dictionaries (you will easily find a lot of documentation with examples on the web), here is a very brief overview:
sage: D = {-1:12, 0:14, 1: 16}
sage: D
{-1: 12, 0: 14, 1: 16}
sage: D[0]
14
sage: D.has_key(-2)
False
sage: D[-2] = 18
sage: D
{-2: 18, -1: 12, 0: 14, 1: 16}
sage: D.keys()
[0, 1, -2, -1]
sage: D.values()
[14, 16, 18, 12]
sage: D.items()
[(0, 14), (1, 16), (-2, 18), (-1, 12)]
sage: for k in D:
....: print k
....: print D[k]
0
14
1
16
-2
18
-1
12
2 | No.2 Revision |
I would suggest to use Python dictionaries (you will easily find a lot of documentation with examples on the web), here is a very brief overview:
sage: D = {-1:12, 0:14, 1: 16}
sage: D
{-1: 12, 0: 14, 1: 16}
sage: D[0]
14
sage: D.has_key(-2)
False
sage: D[-2] = 18
sage: D
{-2: 18, -1: 12, 0: 14, 1: 16}
sage: D.keys()
[0, 1, -2, -1]
sage: D.values()
[14, 16, 18, 12]
sage: D.items()
[(0, 14), (1, 16), (-2, 18), (-1, 12)]
sage: for k in D:
....: print k
....: print D[k]
0
14
1
16
-2
18
-1
12
sage: for k in sorted(D):
....: print k
....: print D[k]
-2
18
-1
12
0
14
1
16