<p><br>
On Apr 25, 2014 7:14 AM, "rahmad akbar" <<a href="mailto:matbioinfo@gmail.com">matbioinfo@gmail.com</a>> wrote:<br>
><br>
> hey guys,<br>
> i am trying to understand this code pasted bellow,<br>
> 1. what is line means? mask[c] |= bit <br>
This bitwise or.  It sets the rightmost bit in masks[c]<br>
> 2. then the line bit *=2, this increment the bit to 2 for each characters<br>
This doubles bit.<br>
> 3. what is this line means? accept_state = bit //2<br>
Integer division<br>
> 4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ c </p>
<p>The << is bitwise shift left<br>
> def ShiftAnd (P , T ):<br>
>   m = len ( P )<br>
>   masks = dict () # empty dictionary<br>
>   bit = 1<br>
>   for c in P :<br>
>     if c not in masks : masks [ c ] = 0<br>
>     masks [ c ] |= bit<br>
>     bit *= 2<br>
>   accept_state = bit // 2<br>
>   D = 0 # bit - mask of active states<br>
>   i = 0<br>
>   for c in T :<br>
>     D = (( D << 1) + 1) & masks [ c ]<br>
>   if ( D & accept_state ) != 0:<br>
>     yield i<br>
>   i += 1<br>
><br>
><br>
You should sprinkle some print statements in and run with various arguments<br>
><br>
><br>
><br>
> -- <br>
> many thanks<br>
> mat<br>
><br>
> _______________________________________________<br>
> Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
> To unsubscribe or change subscription options:<br>
> <a href="https://mail.python.org/mailman/listinfo/tutor">https://mail.python.org/mailman/listinfo/tutor</a><br>
><br>
</p>