Archives week 7 of 2016

Feb. 15, 2016 - Feb. 21, 2016

Python set

1.Method for creating a set

 1)s={1,"python"}
 2)s=set("python") or s=set([1,"python"])
   ps. set to list: 
                   lst=list(s)
       list to set(can remove duplicate elements from the set):
                   s=set([1,"python"])  
       Create an immutable set in "frozenset"

2.Common method of set

 1)add 
    eg.
    b ...

Continue reading

Implementation of Case Swithch syntax in Python

Python itself has no switch statement, there are 3 kinds of Solutions:

1.use dictionary

cases = {
           case1: do_some_stuff1,
           case2: do_some_stuff2,
           ...
           caseN: do_some_stuffN,
         }
cases.get(var, do_default_stuff)()

2.use lambda

result = {
  'a': lambda x: x * 5,
  'b': lambda x: x + 7,
  'c': lambda x: x - 2
}[value](x)

3.Beck Brian provides a class switch to ...

Continue reading

Daily archives

Previous week

Week 6 of 2016

Next week

Week 9 of 2016

Archives