6 kyu

Lexographic sort with a twist

Description:

My 6th kata, implement a lexicographic sort order to make longer items go before any of their prefixes.

In Python, write a function (custom_sort) that takes an input list (lst) of strings. The function should return a new list of strings sorted lexiographically but with longer items before their prefixes. The test cases give some examples.

You can assume that all strings will consist of ASCII printable characters and that the largest character will be '~', which is chr(126). For an extra challenge code a solution that makes no such assumptions.

Do vote and provide any feedback on the kata.

If you like this kata, do checkout my other katas.

Algorithms
Arrays
Sorting
Data Structures

Stats:

CreatedApr 27, 2017
PublishedApr 27, 2017
Warriors Trained439
Total Skips31
Total Code Submissions834
Total Times Completed98
Python Completions98
Total Stars14
% of votes with a positive feedback rating89% of 45
Total "Very Satisfied" Votes38
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes3
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Chris_Rands Avatar
  • siebenschlaefer Avatar
  • saudiGuy Avatar
Ad