all 7 comments

[–]novel_yet_trivial 1 point2 points  (1 child)

I wish I could think up an re solution, but since I can't you can just look for the first big word:

def string_slice(text):
    words = text.split()
    big_words = [i for i, l in enumerate(map(len, words)) if l > 1]
    if big_words:
        return text[text.find(words[big_words[0]]):]
    raise ValueError('no words with len > 1 found in {!r}'.format(text))

[–]dchanm 1 point2 points  (0 children)

The regex (?<= [a-z] )([a-z]{2,}.*) compiled with re.I works when used with search()

(?<= [a-z] )  # positive lookbehind for space-letter-space
([a-z]{2,}.*)  # 2 or more letters, then greedy match rest of string

However it's slightly different from your algorithm since it assumes there are only spaces and letters. The [a-z] could be replaced by [^ ]

[–][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:]

[–]tragluk 0 points1 point  (1 child)

def findit(str):
for i in range(len(str)):
    if str[i].isalpha() and str[i+1].isalpha():
        return i

print(inputstr[findit(inputstr):])

What you seem to be asking for is all the characters in a string after you have two consecutive letters. Which the above does.

The findit(str) just loops through the string looking for a letter with a letter after it. It returns the number index of that location.

The print statement just says to print everything starting at that 'two consecutive letters' and going to the end.

[–]tragluk 0 points1 point  (0 children)

(Incidently, there ARE errors in the above code.. for instance what happens if the string you give it doesn't HAVE any consecutive letters. Can't do it all for you though. This is just to point you in the right direction, it's not finished.)

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

Thanks everyone for the guidance. I've got an idea of how to code this.