Search for '{{search_term}}'

Exercise: Sort based on secondary condition

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

We have a file with strings in it. We would like to sort then according to length. The short strings first. The result is that within the strings of the same length we see them in random order. How can we sort them according to abc? So first come the short strings, but within each length we have abc order.

examples/data/words_to_sort.txt

Foo
Foobar
Bar
Baz
Moo
Another
Reallylong
Shorter

Solutions

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus