Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 2.22 KB

23_10_29_notes.md

File metadata and controls

80 lines (63 loc) · 2.22 KB

Notes

  • 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.

359. Global keyword

  • doesn't seem super important at this point. Can look this up later if needed.

360. Nonlocal keyword

  • Affects the scope of a variable.

361. Why Do We Need Scope?

  • Everything can't be global scope. Firstly, that would be ineffecient. Second, every variable takes up memory.

362. Pure Functions

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.

363. map()

  • 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

364. filter()

-Apply a true/false. Filter out some items.

365. zip()

-A need two iterables and we can zip them together. (I love zip!)

366. reduce()

  • 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]

367 List Comprehensions

-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.

367 List Comprehensions for sets & dictionaries

  • You can apply this to sets and dictionaries.

368 Code Challenge

  • Linked in 368.py

369-377 Videos on setting up PyCharm

  • Probs gonna skip this part.