First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You may use method is_factor:

sage: w = Word('11')
sage: w.is_factor(Word('011'))
True
sage: w.is_factor(Word('101'))
False

To find the first occurrence, you need to reverse the arguments because it searches the input in self:

sage: Word('011').first_occurrence(w)
1
sage: Word('101').first_occurrence(w) is None
True

Or using find as in Python method find for str which returns -1 if not found:

sage: Word('101').find(w)
-1
sage: Word('011').find(w)
1
click to hide/show revision 2
No.2 Revision

You may use the method is_factor:

sage: w = Word('11')
sage: w.is_factor(Word('011'))
True
sage: w.is_factor(Word('101'))
False

To find the first occurrence, you need to reverse the arguments because it searches the input in self:

sage: Word('011').first_occurrence(w)
1
sage: Word('101').first_occurrence(w) is None
True

Or using find as in Python method find for str which returns -1 if not found:

sage: Word('101').find(w)
-1
sage: Word('011').find(w)
1
click to hide/show revision 3
No.3 Revision

You may use the method is_factor:

sage: w = Word('11')
sage: w.is_factor(Word('011'))
True
sage: w.is_factor(Word('101'))
False

To find the first occurrence, you need to reverse the arguments because it searches the input in self:

sage: Word('011').first_occurrence(w)
1
sage: Word('101').first_occurrence(w) is None
True

Or using find as in Python method find for str which returns -1 if not found:

sage: Word('011').find(w)
1
sage: Word('101').find(w)
-1
sage: Word('011').find(w)
1