I have following task

1. determine the longest strings that have not yet been written out
2. among the strings with the longest length that were not written out, select the smallest lexicographically
3. write out the selected line, go to the first item, if there are still unwritten lines

I have following code

```
strings = ['5', 'z', 'yy', 'y', 'zyz', 'zzz']
strings = [x for x in strings if not x.isdigit()]

result = []
for _ in range(0, len(strings)):
    value = max(strings, key=len)
    result.append(strings.pop(strings.index(value)))

print(result)

```

Example: `input array ['5', 'z', 'yy', 'y', 'zyz', 'zzz'] -> output ['zyz', 'zzz', 'yy', 'y', 'z']`

But i have an erorr here, my program returns `['zyz', 'zzz', 'yy', 'z', 'y']`

The other correct example `input array [5, dbccdacaac, abcddbbaab, ccaaaccdab, cdaadbcbdc, dcabdabccb] -> output [abcddbbaab, ccaaaccdab, cdaadbcbdc, dbccdacaac, dcabdabccb]`

How to sort array according to length and smallest lexicographically ?