Thursday, 23 January 2014

Week 2: Points Covered

property - allows regulation of unwanted user changes
var = property(get_var, set_var, remove_var, None)

Stack
methods:
1. __init__() - initializes items
2. push() - put item on top of stack (end of items)
3. pop() - remove item on top of stack (end of items)
4. isempty() - checks if items is empty (to prevent unwanted popping of empty stack)


unittest.Testcase - makes sure implementation is consistent with interphase
import unittest
from filename import Classname

class ClassnameEmptyTestCase(unittest.TestCase):
...

3 Shortcuts on Python:
1. sets
list1 = [1,2,3]
list2 = [2,3,4]
set(list1) - set(list2) = (1) #things in list1 not in list2
set(list1).intersection(set(list2)) = (2,3) # things in both list1 and list2

2. list comprehensions - returns new list with expression applied to every item in list
new_list = [expression for item in list]

*does its work for tuples?

3. ternary if - replaces if...else body
expression1 if condition and else expression2

Recursion - when tracing, don't trace every single calculation. if result is calculated from a recursive call (that is simple), simply replace the expression with the result

No comments:

Post a Comment