0

I am trying to complete a function that takes in a list of strings and prints the first letter of each string. I defined the function as firstLetter(lst). and defined the list as lst = ["one", "two", "longer statement"]. However, the function doesn't seem to be reading the list as the function returns nothing. I'll leave the code I used in the relevant section. Thanks for your help.

lst = ["one", "two", "longer statement"]

def firstLetter(lst):
    for item in lst:
        print(item[0]) 

I tested the loop inside the function, it seems to work on its own, but I can't seem to feed the list through the function. I am expecting to see:

0
t
l

However, the function returns nothing.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Dreadscorn
  • 11
  • 3
  • you have to call your function. you are not calling the function. declaring it is not sufficient – njzk2 Jul 09 '19 at 03:24
  • This isn't a duplicate of "What's the purpose of the return statement". The problem with the function is not the lack of a return statement. –  Jul 10 '19 at 01:36

1 Answers1

0

You need to call the function.

lst = ["one", "two", "longer statement"]

def firstLetter(lst):
 for item in lst:
  print(item[0])


firstLetter(lst)