# Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution:

def answer(l):
return sorted(l, key=lambda s: [int(i) for i in s.split('.')])


In this code, I am essentially taking the list, and splitting each element by '.', converting them to integers, and then sorting the list. One thought is to use list comprehension to remove lambda altogether, but unsure how to achieve it.

• What does "no modules" mean? You want to avoid any imports or are modules from the standard library fine? – 409_Conflict Jul 29 '18 at 12:21
• I meant no imports. – user40929 Jul 29 '18 at 16:03
• And what is the reason for such odd constraint? – 409_Conflict Jul 29 '18 at 19:22
• It's a code challenge. – user40929 Jul 29 '18 at 23:15

The best way would be to use the distutils.StrictVersion as your sort key argument.
However, as you do not want to use imports, you may choose to copy the _cmp, __eq__, __le__ and other comparison methods as applicable, from the source file linked above. You'd also modify the parse method to use str.split instead of a regex matching.