Skip to content

Instantly share code, notes, and snippets.

@LouisdeBruijn
Last active February 13, 2021 00:55
Show Gist options
  • Save LouisdeBruijn/c20638c1e6c4c401f188b349831c80f0 to your computer and use it in GitHub Desktop.
Save LouisdeBruijn/c20638c1e6c4c401f188b349831c80f0 to your computer and use it in GitHub Desktop.
list1 = [102, 306, 918, 2754]
list2 = [1, 3, 9, 27]
averages = []
for idx1, el1 in enumerate(list1): # first for-loop
for idx2, el2 in enumerate(list2): # second for-loop
if idx1 == idx2: # check whether the indexes of first * second for-loop match
y_intercept = el1/el2
averages.append(y_intercept)
>>> averages
[102.0, 102.0, 102.0, 102.0]
averages = []
for el1, el2 in zip(list1, list2): # loop through both list using zip
y_intercept = el1/el2
averages.append(y_intercept)
>>> averages
[102.0, 102.0, 102.0, 102.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment