So I have a list for a school assignment.
newEngland = ["Maine","New Hampshire","Vermont", "Rhode Island",
"Massachusetts","Connecticut"]
I have to write a code using a "for" loop to isolate each individual element in the list and count the number of letters in that element. Output should look something like so
In [70]: problem2_3(newEngland)
Maine has 5 letters.
New Hampshire has 13 letters.
Vermont has 7 letters.
Rhode Island has 12 letters.
Massachusetts has 13 letters.
Connecticut has 11 letters.
The code i write has to work for any other list that someone wanted to test it on so it can not be specific to this list
My first idea was to write the following
def problem2_3(ne):
for let in ne:
print(len(ne[let]))
print(ne[let],"has",len(ne[let]),"letters.")
Using this code I get a type error "list indices must be integers or slices, not str"
I have played around with the code but everything I try returns the same type error. Im only a couple weeks into python so sorry if this is a dumb question. Help me out guys!! Thanks.