def square(num):
"""
this returns a square
"""
return num*num
square(3)
# IMPETUS: I want to multiply this list-o-nums times 2
# PROBLEM: That's so manual!
# SOLUTION: Write a function & then MAP the list-o-nums to that function!
def times2(num):
return num * 2
numbers = [1,2,3,4,5]
numbersTimes2 = list(map(times2,numbers))
numbersTimes2 # checking our work
# PROBLEM: That still looks like A LOT of code to do something so little!
# SOLUTION: Put it on one line!
def times2(num): return num * 2
numbers = [1,2,3,4,5]
numbersTimes2 = list(map(times2,numbers))
numbersTimes2 # checking our work
# PROBLEM: That is STILL a lot!
# SOLUTION: USE A LAMBDA!! (it basically just removes the unecessary extra words!)
## BEFORE
def times2(num): return num * 2
## AFTER
lambda num: num * 2
# Get all odd numbers
list(filter(lambda x: x%2, numbers))
name = "kendra"
# name. <-- check the methonds on a string!
d = {'k1': 1, 'k2':2}
# d. <-- check the methods on a dictionary!
lst = [2,3,4,5]
# lst. <-- check the methods on a list!
my_tup = [(1,2),(3,4),(5,6)]
for a,b in my_tup:
print(a)