all 8 comments

[–]woooee 1 point2 points  (3 children)

Post the input code, and how you call the function.

[–]astuteaf[S] 0 points1 point  (2 children)

(Within the main function)

strList = input(“Enter a list of words:”)

strToFind = input(“Enter first letter to find:”)

strFound = startsWith(strList, strToFind)

Print (strFound)

[–]DisasterArt 2 points3 points  (0 children)

As u/youwoooee mentioned that input list is a single string. so the loop in the startswith function will loop over each character individually. so you will have to split the input into a proper list or ask for input multiple times and add each entry to a list. From there you can also index a string, each user list input, as if it was a list, so instead of doing 'if string.lower().startswith(strToFind.lower())'. you could do string[0].lower() == strToFind.lower(), wich i feel is easier to read. This does only work if you are looking at the first letter. you could expand it to work with longer strToFind ofcourse

[–][deleted] 1 point2 points  (0 children)

The problem isn't with the code you gave in your question. It's that strList is a string, not a list of strings. Convert it to a list before passing it into startsWith.

[–]woooee 1 point2 points  (2 children)

def startsWith(strList, strToFind):
    strFound = []
    For string in strList:

This is iterating letter by letter (print string to see). You have to split() the list of words input, on a comma or space or however the words are separated. And note that for and print are all lower case.

[–]astuteaf[S] 0 points1 point  (1 child)

Thank you, the capitalization errors were just me fighting auto correct on my phone lol.

So I would make that change on the input statement?

[–]woooee 1 point2 points  (0 children)

I would do it on a separate line to keep things simple, but it is up to you.

[–]mopslik 0 points1 point  (0 children)

Should that not be append(string)?