I'm trying to know how many spaces in list for words
list = ["Hello Hello Hello Hello"]
How can I do it?
list = ["Hello Hello Hello Hello"]
def readSpace():
print(list.space())
I'm trying like this :
thx.
I'm trying to know how many spaces in list for words
list = ["Hello Hello Hello Hello"]
How can I do it?
list = ["Hello Hello Hello Hello"]
def readSpace():
print(list.space())
I'm trying like this :
thx.
You can use string.count
method to count the number of occurrences of a character in a string:
>>> lst = ["Hello Hello Hello Hello", "exa mple"]
>>> [x.count(" ") for x in lst]
[12, 3]
So, you can modify your method to:
def count_spaces(lst):
return [x.count(" ") for x in lst]
Note that using list
as variable name is a poor choice of variable name because it clashes with built-in list
, and so you should avoid using it.