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
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
>>
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
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
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,
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):
>> >
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
>
>
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(
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
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
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:
> >
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
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
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
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 =
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
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
17 matches
Mail list logo