如何在python列表中查找项的实例数

Dav*_*nus 0 python list

我希望脚本的一部分是这样的.

if list[1] is in list.pop n times:
      return True
Run Code Online (Sandbox Code Playgroud)

mis*_*hik 6

只需使用:

list.count(element)
Run Code Online (Sandbox Code Playgroud)

例:

>>> [1,2,3,4,2,1].count(1)
2
Run Code Online (Sandbox Code Playgroud)