Velocity Reviews > Reoedering indexes in list of list

# Reoedering indexes in list of list

Toto
Guest
Posts: n/a

 09-28-2010
Hello,

I have a list of list
assume myList[x][y] is integer
I would like to create an alias to that list which I could call this
way:
alias[y][x] returns myList[x][y]

how can I do that ? (python 2.6)

(I have a feeling I should use 'property'

Thanks,
--

Chris Rebert
Guest
Posts: n/a

 09-28-2010
On Tue, Sep 28, 2010 at 11:55 AM, Toto <(E-Mail Removed)> wrote:
> Hello,
>
> I have a list of list
> assume myList[x][y] is integer
> I would like to create an alias to that list which I could call this
> way:
> alias[y][x] returns myList[x][y]

alias = zip(*myList)

Cheers,
Chris
--
http://blog.rebertia.com

Toto
Guest
Posts: n/a

 09-28-2010

> alias = zip(*myList)

a=[['00','01'],['10','11']]
l=zip(*a)
print(l)

returns... [('00', '10'), ('01', '11')]

IS NOT AT ALL WHAT I WANT

What I want is

print a[1][0]
'10'
but print l[1][0]
'01'

notice the indexes of the list l are inverted...

Toto
Guest
Posts: n/a

 09-28-2010
again I want:

alias[y][x] returns myList[x][y]

> print a[1][0]
> '10'
> but print l[1][0]
> '01'
>
> notice the indexes *of the list l are inverted...

Toto
Guest
Posts: n/a

 09-28-2010
heu.... the zip trick actually works... my mistake!

Arnaud Delobelle
Guest
Posts: n/a

 09-28-2010
Toto <(E-Mail Removed)> writes:

>> alias = zip(*myList)

>
>
>
> a=[['00','01'],['10','11']]
> l=zip(*a)
> print(l)
>
> returns... [('00', '10'), ('01', '11')]
>
> IS NOT AT ALL WHAT I WANT
>
> What I want is
>
> print a[1][0]
> '10'
> but print l[1][0]
> '01'
>
> notice the indexes of the list l are inverted...

Ahem...

>>> a = [['00', '01'], ['10', '11']]
>>> l = zip(*a)
>>> a[1][0]

'10'
>>> l[1][0]

'01'

Looks *exactly* like what you want to me. It doesn't take that long to
check.

--
Arnaud

Andreas Waldenburger
Guest
Posts: n/a

 09-29-2010
On Tue, 28 Sep 2010 11:55:18 -0700 (PDT) Toto <(E-Mail Removed)>
wrote:

> Hello,
>
> I have a list of list
> assume myList[x][y] is integer
> I would like to create an alias to that list which I could call this
> way:
> alias[y][x] returns myList[x][y]
>
> how can I do that ? (python 2.6)
>
> (I have a feeling I should use 'property'
>

The zip thing certainly seems nice. But I can never get my head around
zip quick enough to not be confused by it. So my initial idea would
have been a function:

def reverse_indices(lst, x, y):
return lst[y][x]

(or, possibly, a subclass of list with this as an additional method.)

Granted, the invocation is different from what you want, but I don't
know enough about your problem to judge whether this is an issue.

/W

--
INVALID? DE!