Last active
July 4, 2021 21:19
-
-
Save thecraftman/140e7a7a49911b639d920715ce32aa58 to your computer and use it in GitHub Desktop.
Python Generators - why to use them and the benefits you receive
This file contains hidden or 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
def square_numbers(nums): | |
result = [] | |
for i in nums: | |
result.append(i*i) | |
return result | |
my_nums = square_numbers([1,2,3,4,5]) | |
# my_nums = [x * x for x in [1,2,3,4,5]] | |
print my_nums # [1, 4 , 9 , 16 , 25] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment