Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit c65a769

Browse files
committed
number_of_occurrences_of_letter -> number_of_letter_occurrences
1 parent 54075cd commit c65a769

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

src/sage/combinat/words/finite_word.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,7 @@ def number_of_subword_occurrences(self, other):
47604760
# return only the number of occurrences of other
47614761
return occ[-1]
47624762

4763-
def number_of_occurrences_of_letter(self, letter):
4763+
def number_of_letter_occurrences(self, letter):
47644764
r"""
47654765
Return the number of occurrences of ``letter`` in ``self``.
47664766
@@ -4774,9 +4774,30 @@ def number_of_occurrences_of_letter(self, letter):
47744774
47754775
EXAMPLES::
47764776
4777-
sage: Word('abbabaab').number_of_occurrences_of_letter('a')
4777+
sage: w = Word('abbabaab')
4778+
sage: w.number_of_letter_occurrences('a')
4779+
4
4780+
sage: w.number_of_letter_occurrences('ab')
4781+
0
4782+
4783+
This methods is equivalent to ``list(w).count(letter)`` and
4784+
``tuple(w).count(letter)``, thus ``count`` is an alias for the method
4785+
``number_of_letter_occurrences``::
4786+
4787+
sage: list(w).count('a')
47784788
4
4779-
sage: Word('abbabaab').number_of_occurrences_of_letter('ab')
4789+
sage: w.count('a')
4790+
4
4791+
4792+
But notice that if ``s`` and ``w`` are strings,
4793+
``Word(s).count(w)`` counts the number occurrences of ``w`` as a
4794+
letter in ``Word(s)`` which is not the same as ``s.count(w)`` which
4795+
counts the number of occurrences of the string ``w`` inside ``s``::
4796+
4797+
sage: s = 'abbabaab'
4798+
sage: s.count('ab')
4799+
3
4800+
sage: Word(s).count('ab')
47804801
0
47814802
47824803
.. SEEALSO::
@@ -4785,7 +4806,7 @@ def number_of_occurrences_of_letter(self, letter):
47854806
47864807
"""
47874808
return Integer(sum(1 for a in self if a == letter))
4788-
count = number_of_occurrences_of_letter # todo: deprecate count ?
4809+
count = number_of_letter_occurrences
47894810

47904811
def _return_words_list(self, fact):
47914812
r"""

src/sage/combinat/words/word_datatypes.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ cdef class WordDatatype_list(WordDatatype):
273273

274274
__add__ = __mul__
275275

276-
def number_of_occurrences_of_letter(self, a):
276+
def number_of_letter_occurrences(self, a):
277277
r"""
278278
Returns the number of occurrences of the letter ``a`` in the word
279279
``self``.
@@ -289,11 +289,11 @@ cdef class WordDatatype_list(WordDatatype):
289289
EXAMPLES::
290290
291291
sage: w = Word([0,1,1,0,1])
292-
sage: w.number_of_occurrences_of_letter(0)
292+
sage: w.number_of_letter_occurrences(0)
293293
2
294-
sage: w.number_of_occurrences_of_letter(1)
294+
sage: w.number_of_letter_occurrences(1)
295295
3
296-
sage: w.number_of_occurrences_of_letter(2)
296+
sage: w.number_of_letter_occurrences(2)
297297
0
298298
299299
.. SEEALSO::
@@ -611,7 +611,7 @@ cdef class WordDatatype_str(WordDatatype):
611611

612612
__add__ = __mul__
613613

614-
def number_of_occurrences_of_letter(self, letter):
614+
def number_of_letter_occurrences(self, letter):
615615
r"""
616616
Count the number of occurrences of ``letter``.
617617
@@ -626,16 +626,16 @@ cdef class WordDatatype_str(WordDatatype):
626626
EXAMPLES::
627627
628628
sage: w = Word("abbabaabababa")
629-
sage: w.number_of_occurrences_of_letter('a')
629+
sage: w.number_of_letter_occurrences('a')
630630
7
631-
sage: w.number_of_occurrences_of_letter('b')
631+
sage: w.number_of_letter_occurrences('b')
632632
6
633-
sage: w.number_of_occurrences_of_letter('c')
633+
sage: w.number_of_letter_occurrences('c')
634634
0
635635
636636
::
637637
638-
sage: w.number_of_occurrences_of_letter('abb')
638+
sage: w.number_of_letter_occurrences('abb')
639639
0
640640
641641
.. SEEALSO::

src/sage/combinat/words/word_generators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ def standard_factorization(self):
290290
break
291291
u = v
292292
w1, w2 = self[:index+1], self[index+1:]
293-
w10 = w1.number_of_occurrences_of_letter(0)
294-
w11 = w1.number_of_occurrences_of_letter(1)
295-
w20 = w2.number_of_occurrences_of_letter(0)
296-
w21 = w2.number_of_occurrences_of_letter(1)
293+
w10 = w1.number_of_letter_occurrences(0)
294+
w11 = w1.number_of_letter_occurrences(1)
295+
w20 = w2.number_of_letter_occurrences(0)
296+
w21 = w2.number_of_letter_occurrences(1)
297297
return Factorization([LowerChristoffelWord(w11,w10),
298298
LowerChristoffelWord(w21,w20)])
299299

0 commit comments

Comments
 (0)