Typefully

What Python data type would [a row of houses] be?

Avatar

Share

 • 

3 years ago

 • 

View on X

What Python data type would [a row of houses] be? ––– Let's look at a residential street with terraced houses I'll call the "object" `row` for row of houses And let's start looking at some properties we want to check for First: can we go from one house to another in order?
Yes, there is an order in which we can go from one house to another. This makes `row` an iterable Second: Does it have a length? Clearly it does We can count how many houses there are. In Python-speak, this is a sized object (we can use `len(row)`)
Third: is it clear what membership of the row of houses is? Well, yes If a house is one of the houses in the row of houses, then it's a member of `row`. This makes `row` a container Since `row` is an iterable, sized, and a container, it's a collection
Fourth: can you refer to a house using an integer that reflects the position of the house? Yes!
Even if the house numbers themselves don't start from 0 (are there any streets that start from zero anywhere in the world?) or they don't increase by 1 each time, you can still refer to the "second house in the row of houses", so `row[1]` This makes `row` a sequence
Fifth: Is this sequence mutable? Not really, no If we ignore demolishing and rebuilding a house for the sake of this argument, then those are the houses in `row`, you can't change them, add to them, or remove them So, `row` must be an immutable sequence such as a tuple, say
So next time you're walking down a residential road, think of the street as a tuple of houses! What other everyday items should I add to this series? ––> Submit your suggestions in the replies… Any if you need a refresher on what all the data structure terms mean… twitter.com/s_gruppetta_ct/status/1628341581538549760
Avatar

Stephen Gruppetta

@s_gruppetta_ct

Constantly looking for innovative ways to talk and write about Python • Mentoring learners • Writing about Python • Writing about technical writing