Created
August 8, 2013 00:41
-
-
Save codebynumbers/6180407 to your computer and use it in GitHub Desktop.
Convert a string like '0,1,2,10 - 12, 20-23' into '0,1,2,10,11,12,20,21,22,23'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def conv(ts): | |
| results = Set([]) | |
| parts = ts.split(",") | |
| for part in parts: | |
| if "-" not in part: | |
| results.add(int(part.strip())) | |
| else: | |
| (s, e) = part.split("-") | |
| for i in range(int(s.strip()), int(e.strip()) + 1): | |
| results.add(i) | |
| return ",".join([str(x) for x in sorted(results)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment