
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to check old and new version numbering are correct or not in Python
Suppose we have a strings older and another string newer. These two are representing software package versions in the format "major.minor.patch", we have to check whether the newer version is actually newer than the older one.
So, if the input is like older = "7.2.2", newer = "7.3.1", then the output will be True
To solve this, we will follow these steps −
- older := a list of major, minor, patch code of older
- newer:= a list of major, minor, patch code of newer
- for i in range the size of list older, do
- := older[i], n := newer[i]
- if n > o, then
- return True
- otherwise when n < o, then
- return False
- if n > o, then
- return False
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, older, newer): older = older.split('.') newer=newer.split('.') for o, n in zip(older, newer): if int(n)>int(o): return True elif int(n)<int(o): return False return False ob = Solution() older = "7.2.2" newer = "7.3.1" print(ob.solve(older, newer))
Input
"7.2.2", "7.3.1"
Output
True
- Related Articles
- Program to check programmers convention arrangements are correct or not in Python
- Program to check whether parentheses are balanced or not in Python
- Program to check whether domain and range are forming function or not in Python
- Program to check three consecutive odds are present or not in Python
- Program to check whether elements frequencies are even or not in Python
- Program to check points are forming convex hull or not in Python
- Program to check points are forming concave polygon or not in Python
- Program to check whether two sentences are similar or not in Python
- Program to check whether different brackets are balanced and well-formed or not in Python
- Program to check number of global and local inversions are same or not in Python
- Program to check linked list items are forming palindrome or not in Python
- Program to check given push pop sequences are proper or not in python
- Program to check whether two string arrays are equivalent or not in Python
- Program to check strings are rotation of each other or not in Python
- Program to check all listed delivery operations are valid or not in Python

Advertisements