Skip to content

Instantly share code, notes, and snippets.

@antonva
Created February 1, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonva/c72193f2e265f13057ad to your computer and use it in GitHub Desktop.
Save antonva/c72193f2e265f13057ad to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
def comp(s):
l = []
for i in s.split():
l.append(int(i))
o = ""
for i in range(0,len(l)):
if i == 0:
o += str(l[i]) + " "
elif l[i] == l[i-1]+1:
o += str(l[i]) + " "
t = o.rsplit(" ", 2)
t[0] = t[0][0]+"-"
t[1] += " "
o = "".join(t)
else:
o += str(l[i]) + " "
print(o)
if __name__ == '__main__':
s = input()
comp(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment