Count elements in a list python

前端 未结 6 2091
暖寄归人
暖寄归人 2021-01-26 14:22

I need to be able to count how many of the string \"O\" is in my list

top_board = [
    [None, None, None, None, None, None, None, None, None],
    [None, None,         


        
6条回答
  •  深忆病人
    2021-01-26 14:32

    def count_O(l):
        count = 0
        for sublist in l:
            count += sublist.count("O")
        return count
    
    
    if count_O(top_board) == 0:
        #do something
    

提交回复
热议问题