Last active
February 13, 2021 00:55
-
-
Save LouisdeBruijn/c20638c1e6c4c401f188b349831c80f0 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
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