- This is the beginning of my virtual notes. I have been writing everything down, but I decided today that typing things would be more effecient since it's a mix of code challenges along with notes.
- My goal is to write down at least one thing from each video even if it's simple.
- doesn't seem super important at this point. Can look this up later if needed.
- Affects the scope of a variable.
- Everything can't be global scope. Firstly, that would be ineffecient. Second, every variable takes up memory.
Pure functions have two rules.
A. Given A, it will always return the same B.
B. No side effects
def multiply_by2(li)
new_list = []
for item in li:
new_list.append(item*2)
return new_list
print(multiply_by2([2, 3, 5])
This is an example of a pure function. If you move the print statement to inside the function it is not longer a pure function.
- Keep your data separate from your functions. A function acts on data. The data doesn't need to be entangled with the function.
- Always gets the same number of elements back
-Apply a true/false. Filter out some items.
-A need two iterables and we can zip them together. (I love zip!)
- import from functools import reduce [reduce does not come in the regular python package]
- reduce(foo, data, 0)// def foo(acc, item) return acc + item// [reduce always hurts my brain]
-Unique to python. You can use list comprehensions on lists, sets, and dictionaries
my_list = [param for param in iterable]
print(my_list)
is the formula. Now let's fill it in.
my_list = [char for char in 'hello']
print(my_list)
OR
my_list3 = [num*2 for num in range(0,100)]
COOL!
Finally,
my_list4 = [num**2 for num in range(0,100) in num%2 == 0]
This actually makes a lot of sense to me.
- You can apply this to sets and dictionaries.
- Linked in 368.py
- Probs gonna skip this part.