View lambdas.py
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
# Functions on the go, without assigning them to a variable | |
# Anonymous functions | |
def square(x): | |
return x*x | |
print(square(2)) | |
print((lambda x: x*x)(4)) |
View maps.py
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
#MAPS | |
def addFive(x): | |
return x + 5 | |
nums = [11,22,33,44,55] | |
result = list(map(addFive,nums)) | |
print(result) | |
nums = [11,22,33,44,55] | |
result = list(map(lambda x:x+5,nums)) | |
print(result) |
View lists.py
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
list = [12] | |
print("========= INSERT ============") | |
list.insert(0, 5) | |
print(list) | |
list.insert(1, 10) | |
print(list) | |
list.insert(2, 6) | |
print(list) | |
print("========= REMOVE ============") |
View dictionaries.py
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
ages = {"Cozy": 21, "Mark": 22, "Dan": 25} | |
primary = { | |
"red": [255, 0, 0], | |
"green": [0, 255, 0], | |
"blue": [0, 0, 255] | |
} | |
print(primary["red"]) | |
print(ages["Cozy"]) | |
# Only Immutable objects can be used as keys to dictionaries | |
# Dictionaries and Lists are mutable and cannot be used as keys in a dictionary |
View sets.py
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
my_set = {"apple", "banana", "cherry", "strawberry", "grapes"} | |
# removes an element from the set | |
my_set.discard("banana") | |
print(my_set) | |
# Clear empties the set | |
my_set.clear() |
View tuples.py
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
words = ("spam", "eggs", "sausages") | |
print(words[0]) | |
print(words.count("spam")) | |
print(words.index("eggs")) | |
# They are immutable |
View for_loop.py
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 LOOP | |
words = ["hello", "world", "spam", "eggs"] | |
for word in words: | |
print(word) |
View for_loop_break.py
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 LOOP BREAK | |
fruits = ["apple", "banana", "cherry"] | |
for x in fruits: | |
if x == "banana": | |
break | |
print(x) |
View for_loop_continue.py
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 LOOP CONTINUE | |
fruits = ["apple", "banana", "cherry"] | |
for x in fruits: | |
if x == "banana": | |
continue | |
print(x) |
View for_loop_else.py
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 x in range(6): | |
print(x) | |
else: | |
print("Finally finished!") |
OlderNewer