FAQ: Code Challenge: String Methods - Count Multi X

This community-built FAQ covers the “Count Multi X” exercise from the lesson “Code Challenge: String Methods”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Count Multi X

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

A post was merged into an existing topic: How does python create an empty list?

13 posts were merged into an existing topic: How does split() work?

2 posts were split to a new topic: Printing number as string instead of int [solved]

30 posts were split to a new topic: How does python create an empty list?

3 posts were split to a new topic: Why doesn’t my code work? [solved]

3 posts were split to a new topic: Using slicing instead of a naive approach [solved]

how about this solution?

def count_multi_char_x(word, x):
splited = word.split(x)
joined = “”.join(splited)
return (len(word) - len(joined))/len(x)

5 posts were split to a new topic: Could I just use .count()?

That’s what I came up with too!

def count_multi_char_x(word, x):
  count = word.split(x)
  wordlen= ''.join(count)
   
  return (len(word)-len(wordlen ))//len(x)

can anyone validate this direction of logic? Is it on the right path or have I made a simple task more complex that it needs to be? Is there a more elegant way of doing it?

4 posts were split to a new topic: Can I iterate through the word? [solved]

7 posts were split to a new topic: Iterating through word search with steps? [solved]

I didn’t look at the hint, I automatically did this:

def count_multi_char_x(word, x):
return word.count(x)

Which is exactly the same as my answer to exercise 3, and it worked.
Then i noticed the question about split() below, and looked at the hint.
Can someone explain why you would use split() and not just count the amount of times ‘x’ is in the word?

Because it is an algorithm the lesson is after, not just a built in method. We are to write the algorithm that will do what the method does.