Created
October 16, 2021 10:27
-
-
Save h3ik0th/f4c90150d2ab6db5e27d6ac4daa34d65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zipping two or more separate lists to generate a combined list of tuples | |
# example: assume we have multiple values the script has provided; | |
# for instance, different prediction accuracy metrics such as RMSE, MAPE, R-squared | |
# we want to assign each of the results to a specific variable | |
inputs = [1, 0.04, 0.9] | |
# clumsy: manual assignment of a results list and assigning to specific variables: | |
inputs = [1, 0.04, 0.9] | |
rmse = inputs[0] | |
mape = inputs[1] | |
rsq = inputs[2] | |
# better: unpacking of the list | |
rmse, mape, rsq = inputs | |
# collect multiple calculations results in a list | |
acc_values = [rmse, mape, rsq] | |
# define a list of names for these results | |
acc_names = ["RMSE", "MAPE", "R-sq"] | |
# alternative to creating a list: | |
# asterisk * in front of the list variable; and a comma , behind it | |
*acc_names, = "RMSE", "MAPE", "R-SQ" | |
acc_names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment