Module 6: Semi structured data to tables
Creating dictionaries to represent data at different aggregations
Differing data representations allow us to group data according to different arrangements. This is different from just aggregarion where we are asking for summary information and often collapsing rows.
Using for loops to look ahead and look back:
Sometimes you need to use a prior value
Classically, you can see this within min and max functions.
Use enumerate() to get the index and the content at the same time
Skip the first value to as your base case
This pattern allows you to look back by one element, but requires that you skip the first one since there isn't anything prior.
while loops
Can be good for this because you are usually messing with the index values at the same time.
There are many ways to use these, but you can do it with a sentinel value that you directly flip from True to False. The while loop will run so long as the boolean value it is evaluating evaluates to True. Being careful with your variable names is key to help you keep the values and logic straight.
So when is a while loop really necessary?
When you don't know how many times you need to run something. This usually happens when you are working with interactive programs (e.g. games) and simulations. There are plenty of other cases, like certain algorithms, etc. as well. We'll get into that later.
Last updated