11 Comments

Ngl when I read the title I thought you were going to discuss the tree data structure 🤣

I liked the journey, it was fun to read. I was thinking though that if individual trees can’t be told apart from one another, chances are you aren’t interested to identify specific trees. In that case, grouping them by species for example would be more useful to use as a key. But as you said, it depends on what you want to do with the data.

Expand full comment
author

Indeed, it very much depends on what the data is needed for!

Expand full comment

I can't say I've ever done it in regard to actual trees, but I'm with you on constantly thinking about how I'd implement something. And data structures are a central part of that. I often end up banging out some Python. (Did it just last week on a Numberphile video I saw.)

Long ago I mentored a buddy of mine through an adult education CS degree. He mentioned that his teachers said the Data Structures class tended to filter out the wannabes. If you can wrap your head around the abstractions needed to design data structures, you have the necessary mindset to design code. I think that's about right.

Expand full comment
author

Being able to choose the "right" data structure for the job is indeed a task much harder than it might seem at first!

Expand full comment

Yes true. In grid it feels intuitive. Trees seem to be something concrete, they might deserve a name or number and they can be used as key. That only feels natural.

Expand full comment

I'm not sure how the geographical coordinates can be the key when they are yet another property of a tree. Seems suited to the purpose, but thinking generally, it seems somewhat counterintuitive.

Expand full comment
author

The key in a dictionary is how you want to be able to access the value. Often, it's a label, like an attribute name, but it's whatever you want to use to be able to access a value.

Expand full comment

I have found the "is it a key or property" question common with dictionary data structures. It seems generally the case that keys are also properties, and as Stephen says, it boils down to how you choose to index the dictionary. When looking for a value, what's the most likely piece of info you'll have for indexing?

Coordinates make a sensible key system in that iterating through the keys gives you all the tree locations. It makes it easy to partition off trees geographically.

Expand full comment
author

The main point is that the right data structure depends on how the data is meant to be used. You need a way to access each tree, and as they're not a sequence (we _could_ make them a sequence, but I don't think that makes much sense, either), then their geographic location is a good way of identifying each tree.

And they're unique, too!

Expand full comment

Yes, makes sense. Just that it felt somewhat counterintuitive.

Expand full comment
author

You're correct that it's not the most common use for a key in a dictionary. A similar and more common use is to refer to positions in a grid, for example (assuming you're not using NumPy or other packages). A dictionary can represent a grid with a tuple with the coordinates as keys, such as `(0, 0)`

Expand full comment