Unpacking Lists
- 01:51
How to unpack a list into individual variables by assigning each object in the list to a new variable.
Downloads
No associated resources to download.
Glossary
lists Machine Learning PythonTranscript
Now you're going to unpack this new list called results into the individual objects contained in that list. To unpack a list, you're going to want to pass the list as a definition to multiple new variables. The number of new variables must match the number of objects in the list, and each new variable must be separated by a comma. Check out the example here. I've created this simple list called example list, and it contains three objects, the integers one, two, and three. To unpack this example list, I create three new variables called one, two, and three. And notice that these three variables are separated by commas. Then I set those equal to my example list. When I execute that cell, the one, two, and three integer from example list are unpacked in order into these three new variables. So when I print variable one, print variable two and print variable three, you can see that the objects in example list have been individually unpacked into those new variables. That's exactly what you need to do with this new list called results. As you can see from this last cell, results contains first a data frame with 80% of the inputs, which are 641 observations. Then another data frame with 20% of the inputs or 161 observations. Third, we have a series with 80% of the target variable values for 641 observations. And then finally, we have a series with 20% of the target variable values, 161 observations.