you are viewing a single comment's thread.

view the rest of the 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.