Created
October 15, 2021 15:49
-
-
Save h3ik0th/7c96f942d2f636752b3040bea69d6d13 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
# small list of random numbers: the jurassic way to square them in a for loop | |
rands = [random.randrange(1, 100, 1) for i in range(5)] | |
print(rands) | |
# list of random numbers: the jurassic way to square them in a for loop | |
rands2 = [] | |
for n in rands: | |
n = n**2 | |
rands2.append(n) | |
print(rands2) | |
# list comprehension to square them | |
c = [n**2 for n in rands] | |
c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment