Ask coding questions

← Back to all posts
Please help me with my program
Kwolski (38)

Hey, I am trying to loop back into the list and find a specific word and to see how many times this specific word appears in the list and then print it out.

Please help,
Kwolski(18)

Answered by AlexanderTarn (270) [earned 5 cycles]
View Answer
Commentshotnewtop
AlexanderTarn (270)

the code says
"print("stop forking our code")"

Kwolski (38)

@AlexanderTarn sorry some kids in class were trying to fork my code I put the real one up though

AlexanderTarn (270)

@Kwolski in the loop where you are checking what word there is make it
for i in range(len(List you have)):
after that with every word
if "Word" == List you have[i]:
variable+=1
hope this helps

Kwolski (38)

@AlexanderTarn thanks so much this is just what I needed

AlexanderBirabe (100)

Well despite the fact you don't seem to have the correct repl attached, I'll still answer your question

myList = ['a', 'a', 'b', 'c', 'c', 'c', 'd']
specificLetter = 'c'
howMany = 0

for letter in myList:
  if letter == specificLetter:
    howMany += 1

print(howMany)

The for letter in myList: just creates a loop that goes through each element in myList. So first it runs the code below it with the vale of letter being 'a', then 'a' again, then 'b', then 'c'...