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?
What you do is actually removing the search string in the text (split by x then join with empty string). You could acheive same thing just by simple replace:
According to the solution code, when executing the first print comment(mississipi), how come the splits list get the elements of “m”, " ", “ipi”?
I thought it will get “m” and “ipi” only.
[spoiler]This text will be blurred[/spoiler]
# Write your count_multi_char_x function here:
def count_multi_char_x(word, x):
splits = word.split(x)
return(len(splits)-1)
# Uncomment these function calls to test your function:
print(count_multi_char_x("mississippi", "iss"))
# should print 2
print(count_multi_char_x("apple", "pp"))
# should print 1[spoiler]This text will be blurred[/spoiler]
if you know what each thing there does then you can carry it out with pen and paper and observe what you do
or if not, then find out what that individual thing does before considering all of it at once. it’s not some impenetrable blob, there are individual parts that you need to learn before you can understand the overall thing
and, if there are individual parts in it that you can learn about, then maybe doing so lets you understand the overall thing and therefore don’t need to ask for help with it quite yet
I understand what each thing there does, but I’m confused on why we’re splitting at x. I also don’t know why we’re returning the length of the split and then putting the -1. I just started learning python and some of these things aren’t making sense, sorry for sounding a little stupid.