Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Created October 16, 2021 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3ik0th/f4c90150d2ab6db5e27d6ac4daa34d65 to your computer and use it in GitHub Desktop.
Save h3ik0th/f4c90150d2ab6db5e27d6ac4daa34d65 to your computer and use it in GitHub Desktop.
# 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