0

I'm trying to compare strings in Python that can be different lengths. This is to do a simple version check. Here are the examples: 1.2.3, 1.2.15, 1.2.2a

I need to compare to find which one is bigger so taking example above 1.2.2a < 1.2.3 < 1.2.15. If there were only number than it would be pretty simple but the added character messes things as it is not always present. I thought that converting to base64 which makes string the same length will solve the problem but with base64 1.2.15 becomes less than 1.2.2a and 1.2.3. Maybe there is a module that already does that. Thank you.

2
  • You probable want to look at the re module - regular expressions will be able to isolate the letter from the numbers. What would happen, for example, if you got 1.2.2a and 1.2.2b? Commented Jul 4, 2017 at 11:54
  • "base64 which makes string the same length"? Wat. Commented Jul 4, 2017 at 11:57

1 Answer 1

3

The version numbers you are using appear to confirm with the semantic versioning standard. There are libraries available to handle this for you - take a look at semver or semantic_version.

Sign up to request clarification or add additional context in comments.

2 Comments

Welcome to SO. If this answered your question (unless, of course, someone answers it better :-)) please feel free to mark it as accepted. In this case it appears the question may be closed as a duplicate of this question which may give you some more ideas.
Thanks for quick response this is what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.