Efficiently check if an element occurs at least n times in a list

后端 未结 7 2173
南旧
南旧 2020-12-07 00:23

How to best write a Python function (check_list) to efficiently test if an element (x) occurs at least n times in a list (l

相关标签:
7条回答
  • 2020-12-07 01:19
                                           c=0
                                           for i in l:
                                               if i==k:
                                                  c+=1
                                           if c>=n:
                                              print("true")
                                           else:
                                              print("false")
    
    0 讨论(0)
提交回复
热议问题