1 | initial version |

I would use a different data structure, namely a dictionary:

```
p = {(k,l) : var(f'p_{k}{l}') for k in range(2) for l in range(4)}
```

Then you can do:

```
sage: p[0,0]
p_00
sage: p[1,2]
p_12
```

And if you want, you can define your flattened list `z`

based on this dictionary:

```
z = [p[k,l] for k in range(2) for l in range(4)]
```

2 | No.2 Revision |

I would use a different data structure, namely a dictionary:

```
p = {(k,l) : var(f'p_{k}{l}') for k in range(2) for l in range(4)}
```

Then you can do:

```
sage: p[0,0]
p_00
sage: p[1,2]
p_12
```

And if you want, you can define your flattened list `z`

based on this dictionary:

```
z = [p[k,l] for k in range(2) for l in range(4)]
```

And to go from a variable to a tuple of indices you can define an "inverse" dictionary:

```
p_inverse = {v:k for k,v in p.items()}
```

Indeed:

```
sage: p_inverse[p[1,2]]
(1,2)
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.