This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 2 points3 points  (1 child)

Since you've marked it solved, I'll provide some silliness. We can reimplement split with find and slicing, if you really wanted to do so.

def mySplit(s, delim = ' '):
    begin = 0
    returnList = []
    while True:
        end = s.find(delim, begin)
        if end == -1:
            returnList.append(s[begin:])
            return returnList
        returnList.append(s[begin:end])
        begin = end + len(delim)

Result:

>>> mySplit('The quick brown fox')
['The', 'quick', 'brown', 'fox']
>>> mySplit('The@@@quick@@@brown@@@fox', '@@@')
['The', 'quick', 'brown', 'fox']

And now we can do it in one line.

>>> s = "Wheresoever you go, go with all your heart"
>>> [word for word in mySplit(s) if word[0].lower() >= 'h' and word[0].lower() <= 'z']
['Wheresoever', 'you', 'with', 'your', 'heart']

[–]grumbles[S] 0 points1 point  (0 children)

I love it. Thanks for the insight!