Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Created October 15, 2021 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3ik0th/7c96f942d2f636752b3040bea69d6d13 to your computer and use it in GitHub Desktop.
Save h3ik0th/7c96f942d2f636752b3040bea69d6d13 to your computer and use it in GitHub Desktop.
# 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