我有这个清单:
['Boston Americans', 'New York Giants', 'Chicago White Sox', 'Chicago Cubs', 'Chicago Cubs', 'Pittsburgh Pirates', 'Philadelphia Athletics', 'Philadelphia Athletics', 'Boston Red Sox', 'Philadelphia Athletics', 'Boston Braves', 'Boston Red Sox', 'Boston Red Sox', 'Chicago White Sox', 'Boston Red Sox', 'Cincinnati Reds', 'Cleveland Indians', 'New York Giants', 'New York Giants', 'New York Yankees', 'Washington Senators', 'Pittsburgh Pirates', 'St. Louis Cardinals', 'New York Yankees', 'New York Yankees', 'Philadelphia Athletics', 'Philadelphia Athletics', 'St. Louis Cardinals', 'New York Yankees']
假设我想计算"Boston Americans"
在列表中的次数。你知道吗
如果不使用.count
方法list.count("Boston Americans")
或任何导入,我怎么做呢?你知道吗
还有一种使用
sum
的方法:这里,我们使用的事实是
True
和False
可以被视为整数0和1。你知道吗数数:)
您可以使用内置的^{} 函数:
相关问题 更多 >
编程相关推荐