Skip to content

Instantly share code, notes, and snippets.

Created Oct 16, 2021
What would you like to do?
# 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment