![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements