0

If i have this

a = "4.1.3.79"
b = "4.1.3.64"

How can i make this comparison to return True?

a > b

I cant use float() or int() and python doesn't recognize 4.1.2.79 as a number, How can i do comparison's with these types of values?

I have read up on StrictVersion but that only goes up to 3rd version number, and not 4.

Mfreeman
  • 3,548
  • 7
  • 23
  • 37

1 Answers1

1

this will work:

a = "4.1.2.79"
b = "4.1.3.64"
#split it
a_list = a.split('.')
b_list = b.split('.')
#to look if a is bigger or not
a_bigger = False
#compare it number by number in list
for i in range(0, len(a_list)):
    #make from both lists one integer
    a_num = int(a_list[i])
    b_num = int(b_list[i])
    #if one num in the a_list is bigger
    if a_num > b_num:
        #make this variable True
        a_bigger = True
        #break the loop so it will show the results
    #else it wil look to the other nums in the lists
#print the result
print('a > b: %s' % str(a_bigger))
Matthijs990
  • 637
  • 3
  • 26