0

I need to print value with some size using condition.

size, url
1 https://api-glb-ams.smoot.apple.com/user_guid?
3257 https://init.itunes.apple.com/WebObjects/MZInit.woa/wa/signSapSetupCert
0 http://engine.rbc.medialand.ru/code?
35 http://www.google-analytics.com/collect?
0 http://engine.rbc.medialand.ru/test?
0 http://engine.rbc.medialand.ru/code?

I get it in loop and I try to get all url, where size more than 43.

if not size:
    continue
elif size[0] < 43:
    continue
else:
    print size[0], url

If condition works, but elif doesn't. It print all size and url

1
  • Are you reading this from a file? If then the issue can be with the string type Commented May 16, 2016 at 8:45

1 Answer 1

2

In Python 2, which you are using, strings can be compared to integers. Strings always compare as being larger than integers.

>>> '35' < 43
False

To solve this, wrap the string in an int() call:

>>> int('35') < 43
True

For your program:

elif int(size[0]) < 43:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.