Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python what's the data structure for triple data

I've got a set of data that has three attributes, say A, B, and C, where A is kind of the index (i.e., A is used to look up the other two attributes.) What would be the best data structure for such data?

I used two dictionaries, with A as the index of each. However, there's key errors when the query to the data doesn't match any instance of A.

like image 688
Paul Avatar asked Jun 03 '26 10:06

Paul


2 Answers

AtoB = {"A1":"B1", "A2":"B2"}
AtoB.get("A3", None)
=> None
like image 101
gilesc Avatar answered Jun 05 '26 23:06

gilesc


Could you use a dictionary with A as the key, and the item in the dictionary as a 2-item tuple or list? If you're working with any of that data in a consistent way, you could also consider storing a class that has 2 properties in the dictionary.

like image 31
Jordan Avatar answered Jun 05 '26 23:06

Jordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!