I am having difficulty with one of my homework questions.
Basically, I am to create a function using a for loop to count the characters used in strings which are inside of a list. I am able to get the length of the strings with len(), but I can only get one of the strings and I can't seem to get it in list form.
My Code:
def method1(input1):
total = 0
a = []
for word in input1:
total = len(word)
a = [total]
return a
This returns [3] with the input ['seven', 'one']
Any help would be appreciated. I am very new to Python.
return sum([len(a) for a in input1])a += [total]. this returns the length of strings in a list form. So if your input is['Seven', 'one']. It will return ` [5,3]`