Created
December 7, 2017 18:06
-
-
Save RedGhoul/965aa3885dad2f3bd8abb58e0963537f 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
#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