def functionOne(shortWord, longWord):
character = shortWord[0]
I am at a loss right now, I need to find the index value of the first letter of shortWord
's first occurrence in longWord
but I can't use concepts such as find()
or index()
. How would I compare the two to get the value?
for example: if the arguments were abcdefghijklmnop
and cdef
I need to return an index value of 2.
Edit: I can only use slicing and basic indexing concepts such as getting the index value or range using [#]. I cannot use external functions.
Edit #2: The question posed is as follows: Using string slicing and indexing concepts find the location of the second argument within the first. The index value of the beginning of the second argument will be returned by the function.
CodePudding user response:
Maybe you can loop trow the string while comparing. Some thing like this:
def functionOne(shortWord, longWord):
for position in range(len(longWord) - len(shortWord)):
if shortWord == longWord[position: position len(shortWord)]:
return position
CodePudding user response:
Thanks for the help everyone sorry for wasting your time, I will just have to move on from the question for now.