Is there a way to simplify this
Not exactly in the way you are proposing. In the rest of the missions you will learn about for loops and you will be able to simplify the solution so that it’s not “hardcoded” in a way.
Later, you will learn some more advanced ways to easily sum across multiple lists. I can share some off that code, but it’s best that you slowly build on top of each “knowledge step”. If you’d rather get to see some of that code now, let me know.
But it’s great you are trying different things out!
is there a way to select the first and last two data points through code like
That depends on
row_1. Or rather, what type of “container” it is for storing data. Till now, and I think for a few more missions, you will only be working with
For lists, what you suggest is not possible. When attempting to extract an item -
You first use
That will give you the first element (the value at the first index) in the list,
row_1. That would be
And then, if you wish to extract something from that string, you can use
slice operator -
It’s a separate slice operation. And the above will give you an
If you wanted to select multiple non-consecutive items from
row_1, like you ask about, that would require some more “advanced” methods that you will learn about later. There are some more advanced aspects to using the
slice operator that will come up later as well.
And the kind of operation you are suggesting,
row_1[0,3:4], that will come up later as well. But it would work for a different kind of data structure/container.
There’s a lot of “will come up later” in my answer. I suggest going through the missions at your pace, but if you still prefer to look at some of the code I can share that too.