grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.']]
I would like to ask if how can I count the values inside the list. In this case, the value would be 6 not 2. Sorry I am not that familiar with the terms. Thanks!
grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.']]
I would like to ask if how can I count the values inside the list. In this case, the value would be 6 not 2. Sorry I am not that familiar with the terms. Thanks!
If you want the length of each nested list you can use a list comprehension
[len(sub_list) for sub_list in grid]
[6, 6]
If you want the unique values of the lengths, you can use a set-comprehension
{len(sub_list) for sub_list in grid}
{6}
this is a list of lists. It would actually look like this, just adding a bracket to the end:
grid = [
['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.']
]