-3

I have a list of number:

a = '15235137835692838387'

how to write code output this in python

output = ["1378","3569"]
  • You forgot to include the code you wrote that produces the incorrect output. – dfundako Aug 15 '19 at 18:50
  • what do you mean by `collection of longest order sequence`? – Poojan Aug 15 '19 at 18:50
  • Welcome to SO. This isn't a discussion forum or tutorial. Please take the time to read [ask] and the other links found on that page. Invest some time with [the Tutorial](https://docs.python.org/3/tutorial/index.html) practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. – wwii Aug 15 '19 at 18:59
  • Flagging as unclear. Your question doesn't explain anything how the output came – Nouman Aug 15 '19 at 19:01
  • Possible duplicate(s) (after converting to a list of ints): [Longest increasing subsequence](https://stackoverflow.com/questions/3992697/longest-increasing-subsequence), [How to determine the longest increasing subsequence using dynamic programming?](https://stackoverflow.com/questions/2631726/how-to-determine-the-longest-increasing-subsequence-using-dynamic-programming), – wwii Aug 15 '19 at 19:04

1 Answers1

0

To answer your quite vague question with a brute force solution:

temp, output = a[0], []
for i in range(len(a) - 1):
    if a[i] <= a[i+1]:
        temp += a[i+1]
    else:
        if temp:
            output.append(temp)
            temp = a[i+1]


# Pulling longest value
maxLen = max([len(el) for el in output])
output = [val for val in output if len(val) == maxLen]

# output = ['1378', '3569']
Adrian
  • 177
  • 13