Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming Pushups part II

Name: Anonymous 2015-01-05 12:04

Write a program to compare two version strings.

Example comparisons:
1.05.00.0156 > 1.0.221.9289
1 < 1.0.1
1.0.1 < 1.0.2
1.0.2 < 1.0.3
1.0.3 < 1.1
1.1 < 1.1.1
1.1.1 < 1.1.2
1.1.2 < 1.2

Name: Anonymous 2015-01-05 12:22

#!/usr/bin/python3

import sys

def version_string_to_integer(vstr):
return int(''.join(s.lsplit('0') for s in vstr.split('.')))

a, b = map(version_string_to_integer, sys.argv[1:3])
if a < b:
print('lt')
elif a > b:
print('gt')
else:
print('eq')


I didn't bother to try if it works since it's so trivial program

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List