the objective is as follows:
Write a function splitWord(word, numOfChar) that takes in a word and a number as arguments. The function will split the word into smaller segments with each segment containing the number of letter specified in the numOfChar argument. These segments are stored and returned in a list.
>>> splitWord('google', 2) ['go', 'og', 'le'] >>> splitWord('google', 3) ['goo', 'gle'] >>> splitWord('apple', 1) ['a', 'p', 'p', 'l', 'e'] >>> splitWord('apple', 4) ['appl', 'e']
I spent ages messing around try to find ways, eventually i got it working and started testing it, however, for some reason it doesn't accept duplicate values?!
def splitWord(word, numOfChar): r =  h = len(word)/numOfChar while True: if len(word) == 0: break else: r.append(word[0:numOfChar:1]) word = word.replace(word[0:numOfChar:1], '') return r
Help would be appreciated, after spending so much time up all night trying to learn and getting stuck on this...
Anyway, thanks for any help.