排队,
Boys dance, girls dance, he dances, she dances
如何计算发生的次数dance
而不计算发生的次数dances
(使用Python程序)?
一种方法是
>>> var = "Boys dance, girls dance, he dances, she dances"
>>> count1 = var.count("dance")
>>> count2 = var.count("dances")
>>> count = count1 - count2
>>> count
2
>>>
但它太长了。
有没有可用的单线方法?