Re: How to use list as key of dictionary?



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:50 pm, Davy <zhushe...@xxxxxxxxx> 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_tuple:'hello'} cause an error?

Best regards,
Davy

On Nov 6, 3:09 pm, Matimus <mccre...@xxxxxxxxx> wrote:



On Nov 5, 10:53 pm, Davy <zhushe...@xxxxxxxxx> 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 = {}
d[tuple([1,2,3,4])] = 'hello world'
d
{(1, 2, 3, 4): 'hello world'}>>> d[1,2,3,4]
'hello world'
Matt- Hide quoted text -
- Show quoted text -


.



Relevant Pages

  • Re: How to count the element of a Set?
    ... > Best regards, ... Prev by Date: ...
    (microsoft.public.vc.stl)
  • Re: Fastcode CharPosRev B&V 0.6.0
    ... so nevermind mine PByteArray stuf:) ... Best regards, ... Davy ...
    (borland.public.delphi.language.basm)
  • Re: Remote desktop access
    ... Really good remote tool and it's free ... Regards ... Am hoping to get some help to connect to my sisters pc to iron out some ... please could you advise Thanks Davy ...
    (microsoft.public.windows.vista.general)
  • 2-port USB hub chip?
    ... Is there exist 2-port USB hub chip? ... Best regards, ... Davy ... Prev by Date: ...
    (sci.electronics.design)
  • 2-port USB hub chip?
    ... Is there exist 2-port USB hub chip? ... Best regards, ... Davy ... Prev by Date: ...
    (sci.electronics.basics)