Data structure question

J

Joseph L. Casale

I have a need for a script to hold several tuples with three values, two text
strings and a lambda. I need to index the tuple based on either of the two
strings. Normally a database would be ideal but for a self-contained script
that's a bit much.

Before I re-invent the wheel, are there any built-in structures that allow for
this type of use case?

Thanks,
jlc
 
N

Ned Batchelder

I have a need for a script to hold several tuples with three values, two text
strings and a lambda. I need to index the tuple based on either of the two
strings. Normally a database would be ideal but for a self-contained script
that's a bit much.

Before I re-invent the wheel, are there any built-in structures that allow for
this type of use case?

Thanks,
jlc

Sounds like you should create a dictionary, and enter each tuple twice, once with each string as a key:

d = {}
for t in the_tuples:
d[t[0]] = d[t[1]] = t

--Ned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top