Skip to content

Instantly share code, notes, and snippets.

@RedGhoul
Created December 7, 2017 18:06
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 RedGhoul/965aa3885dad2f3bd8abb58e0963537f to your computer and use it in GitHub Desktop.
Save RedGhoul/965aa3885dad2f3bd8abb58e0963537f to your computer and use it in GitHub Desktop.
#For Loops
seq = [1,2,3,4,5,6,3]
for item in seq:
print(item)
dick = {"SAM":1,"FRANK":2,"Dan":3}
for it in dick:
print(it) #outputs the keys
print(dick[it]) #outputs the values
myPairs = [(1,2),(3,4),(5,6)]
for item in myPairs:
print(item) # just prints the tuples in the list
# can also be used in: tuple1,tuple2
for (tuple1, tuple2) in myPairs:
#known as unpacking tuples
print(tuple1)
print(tuple2)
#While Loops
i = 0
while i < 5:
print("i is: {}".format(i))
i = i + 1
range(0,20) # generates up to, but not including 20
# is a generator
# have to convert it to a list, to properly use it
for s in list(range(0,22)):
print("YOLO")
# also stuff like "list comprehension"
x = [1,2,3,4,5]
# your taking each value in "x" and taking the power of 2 of it
# then you putting all results into a list by using the square braces
print([num**2 for num in x])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment