On Apr 25, 2014 7:14 AM, "rahmad akbar" <[email protected]> wrote: > > hey guys, > i am trying to understand this code pasted bellow, > 1. what is line means? mask[c] |= bit This bitwise or. It sets the rightmost bit in masks[c] > 2. then the line bit *=2, this increment the bit to 2 for each characters This doubles bit. > 3. what is this line means? accept_state = bit //2 Integer division > 4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ c
The << is bitwise shift left > 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 > > You should sprinkle some print statements in and run with various arguments > > > > -- > many thanks > mat > > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
