0

I am new to python, so my question would be naive but I would appreciate your suggestion that help me get to the solution of it.

For example I have string "aeshfytifghkjgiomntrop" and I want to find ordered substrings from it. How should I approach?

1
  • 1
    what do you mean by ordered strings? Commented Sep 21, 2016 at 7:30

1 Answer 1

1

Scan the string using enumerate to issue index and value. Print string parts when chars are decreasing and start a new substring:

s = "aeshfytifghkjgiomntrop"

prev_c = None
prev_i = 0

for i,c in enumerate(s):
    if prev_c>c:
        print(s[prev_i:i])
        prev_i=i
    prev_c=c
print(s[prev_i:])

result:

aes
h
fy
t
i
fghk
j
gio
mnt
r
op

(No particular Python magic here, could be done simply even with C)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.