The Matrix notes part 1, python labs

  1. <expression1> if <condition> else <expression2>  equals expression i C style: condition ? expression1 ? expression2

  2. Set union and intersection: SetA | SetB,   SetA & SetB

  3. Mutating a set:

    1. S = {1,2,3}; S.update({2,4,5}) // set([1,2,3,4,5])  union
      S.intersecton_update({2,4,5})  // set([2]) intersection
      other functions: copy, add, remove
  4. double comprehension {x*y for x in {1,2,3} for y in {2,3,4}}

  5. Set is mutable and elements in set are must not mutable.  so {{1,2},3} does not work

  6. For dictionary, the key should be mutable: strings, integers, or tuple of strings and integers

  7. Construct a dictionary by a comprehension: { k:v for (k,v) in [(3,2),(4,0),(100,1)] }

  8. Iterate dictionary by iitems():  [myitem for myitem in mydict.items()] and unpacking [ expression for (k, v) in mydict.items()]


play with GF2:

  1. + equals to exclusive or, * equals to ordinary multiplication

  2. usage: 

    1. encryption (perfect secrecy)

    2. network encoding



你可能感兴趣的:(The Matrix notes part 1, python labs)