list.count
is used to get the count of an item in list, but you need to do a substring search in each item to get the count as 4.
>>> data = ['This','is','some','test','data','\nThis','is','some','test','data','\nThis','is','some','test','data','\nThis','is','some','test','data','\n']
Total number of items that contain '\n'
:
>>> sum('\n' in item for item in data)
4
Sum of count of all '\n'
s in data
:
>>> data = ['\n\nfoo','\n\n\nbar']
>>> sum(item.count('\n') for item in data)
5