Skip to content

Instantly share code, notes, and snippets.

@eriky
Last active February 6, 2021 02:10
Show Gist options
  • Save eriky/01f600524220bf77c235b397fe4bf19e to your computer and use it in GitHub Desktop.
Save eriky/01f600524220bf77c235b397fe4bf19e to your computer and use it in GitHub Desktop.
def some_function(a):
return (a + 5) / 2
my_formula = [some_function(i) for i in range(10)]
print(my_formula)
# [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0]
@GadgetSteve
Copy link

Came across this in an article that started with this is Python 3 code but the output above is correct only for Python 2. Output should be:

# [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0]

or some_function should use //

@eriky
Copy link
Author

eriky commented Jan 28, 2020

You are right; I fixed it in the gist. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment