[Tutor] trying to understand pattern matching code

rahmad akbar matbioinfo at gmail.com
Fri Apr 25 13:13:26 CEST 2014


hey guys,
i am trying to understand this code pasted bellow,
1. what is line means? mask[c] |= bit
2. then the line bit *=2, this increment the bit to 2 for each character?
3. what is this line means? accept_state = bit //2
4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ c
def ShiftAnd (P , T ):
  m = len ( P )
  masks = dict () # empty dictionary
  bit = 1
  for c in P :
    if c not in masks : masks [ c ] = 0
    masks [ c ] |= bit
    bit *= 2
  accept_state = bit // 2
  D = 0 # bit - mask of active states
  i = 0
  for c in T :
    D = (( D << 1) + 1) & masks [ c ]
  if ( D & accept_state ) != 0:
    yield i
  i += 1





-- 
many thanks
mat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140425/c5c1476f/attachment.html>


More information about the Tutor mailing list