Re: How to use list as key of dictionary?

2007-11-07 Thread Wildemar Wildenburger
Duncan Booth wrote: > Better, just don't try passing it a recursive data structure. > a = [1, 2, 3] a[1] = a a > [1, [...], 3] tupleize(a) > > > Traceback (most recent call last): > File "", line 1, in > tupleize(a) > File "", line 5, in tupleize > return tuple(t

Re: How to use list as key of dictionary?

2007-11-07 Thread Wildemar Wildenburger
Duncan Booth wrote: > Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > >> maybe something like this could help: >> >> def tupleize(non_tuple): >> try: >> return tuple(tupleize(thing) for thing in non_tuple) >> except TypeError: >> # non_tuple is not iterable >>

Re: How to use list as key of dictionary?

2007-11-06 Thread Steven D'Aprano
On Tue, 06 Nov 2007 11:25:29 +, Duncan Booth wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > > > >> Not quite, because that will also convert strings to tuples, which may >> not be what you want for a general solution. > > I take it you didn't actually try the original code then. N

Re: How to use list as key of dictionary?

2007-11-06 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Not quite, because that will also convert strings to tuples, which may > not be what you want for a general solution. I take it you didn't actually try the original code then. Converting strings to tuples is not something it did. > That works for

Re: How to use list as key of dictionary?

2007-11-06 Thread Steven D'Aprano
On Tue, 06 Nov 2007 10:46:48 +0100, Wildemar Wildenburger wrote: > Davy wrote: > > Hi Matimus and Boris, > > > > Thank you :) > > > > And a further question about vector above rank 1, how can I use it as > > the key of dictionary? > > > > For example, if I have list like L=[[1,2,3],[4,5,6,

Re: How to use list as key of dictionary?

2007-11-06 Thread Duncan Booth
Paul McGuire <[EMAIL PROTECTED]> wrote: > On Nov 6, 4:08 am, Dustan <[EMAIL PROTECTED]> wrote: >> On Nov 6, 3:58 am, Duncan Booth <[EMAIL PROTECTED]> wrote: >> >> > Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: >> > > maybe something like this could help: >> >> > > def tupleize(non_tuple): >> >

Re: How to use list as key of dictionary?

2007-11-06 Thread Boris Borcic
You could also index on the repr() of your objects, which is an immutable str value. Davy wrote: > And there may be more complex list(vector like 3 or 4 dimentional data > structure), is there any easy method to tackle this problem? > > Any suggestions are welcome! > > Best regards, > Davy > >

Re: How to use list as key of dictionary?

2007-11-06 Thread Paul McGuire
On Nov 6, 4:08 am, Dustan <[EMAIL PROTECTED]> wrote: > On Nov 6, 3:58 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > > > Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > > > maybe something like this could help: > > > > def tupleize(non_tuple): > > > try: > > > return tuple(tupleize(

Re: How to use list as key of dictionary?

2007-11-06 Thread Davy
And there may be more complex list(vector like 3 or 4 dimentional data structure), is there any easy method to tackle this problem? Any suggestions are welcome! Best regards, Davy On Nov 6, 4:50 pm, Davy <[EMAIL PROTECTED]> wrote: > Hi Matimus and Boris, > > Thank you :) > > And a further questi

Re: How to use list as key of dictionary?

2007-11-06 Thread Michael Wronna
On Tue, 6 Nov 2007, Boris Borcic wrote: >> We know that list cannot be used as key of dictionary. > Yeah, but do we know why ? I think, because lists are mutable and a key of a dictionary MUST be unmutable, not to crash the dictionary by accidently changing one of its keys! Mike -- http://mai

Re: How to use list as key of dictionary?

2007-11-06 Thread Dustan
On Nov 6, 3:58 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > > maybe something like this could help: > > > def tupleize(non_tuple): > > try: > > return tuple(tupleize(thing) for thing in non_tuple) > > except TypeError: > >

Re: How to use list as key of dictionary?

2007-11-06 Thread Duncan Booth
Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > maybe something like this could help: > > def tupleize(non_tuple): > try: > return tuple(tupleize(thing) for thing in non_tuple) > except TypeError: > # non_tuple is not iterable > return non_tuple > Just do

Re: How to use list as key of dictionary?

2007-11-06 Thread Wildemar Wildenburger
Davy wrote: > Hi Matimus and Boris, > > Thank you :) > > And a further question about vector above rank 1, how can I use it as > the key of dictionary? > > For example, if I have list like L=[[1,2,3],[4,5,6,7]], > Then I do L_tuple = tuple(L) L_tuple = ([1,2,3],[4,5,6,7]) > But {L_t

Re: How to use list as key of dictionary?

2007-11-06 Thread Davy
Hi Matimus and Boris, Thank you :) And a further question about vector above rank 1, how can I use it as the key of dictionary? For example, if I have list like L=[[1,2,3],[4,5,6,7]], Then I do L_tuple = tuple(L) >>> L_tuple = ([1,2,3],[4,5,6,7]) But {L_tuple:'hello'} cause an error? Best regar

Re: How to use list as key of dictionary?

2007-11-05 Thread Matimus
On Nov 5, 10:53 pm, Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > We know that list cannot be used as key of dictionary. So, how to work > around it? > > For example, there is random list like l=[1,323,54,67]. > > Any suggestions are welcome! > > Best regards, > Davy Use a tuple instead. >>> d =

Re: How to use list as key of dictionary?

2007-11-05 Thread Boris Borcic
Davy wrote: > Hi all, > > We know that list cannot be used as key of dictionary. Yeah, but do we know why ? > So, how to work > around it? That's a subsidiary question. > > For example, there is random list like l=[1,323,54,67]. Don't use 1owercase L as a variab1e name, p1ease ! > > Any su

How to use list as key of dictionary?

2007-11-05 Thread Davy
Hi all, We know that list cannot be used as key of dictionary. So, how to work around it? For example, there is random list like l=[1,323,54,67]. Any suggestions are welcome! Best regards, Davy -- http://mail.python.org/mailman/listinfo/python-list