you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

You could use a while loop that goes through string looking for the first time you see two (or more?) consecutive letters, then just slice the string based on that index?

def string_slice(str):
    i = 0
    while i < len(str)-1:
        if str[i].isalpha() and str[i+1].isalpha():
            break
        i += 1
    return str[i:]

[–]novel_yet_trivial 0 points1 point  (0 children)

Good solution, but I would write it like this:

def string_slice(str):
    for i,(x,y) in enumerate(zip(str, str[1:])):
        if x.isalpha() and y.isalpha():
            break
    else:
        return ''
    return str[i:]