1

I have 2 ranges,

range1=range(80, 90)

range2=range(0,360).

I need to check if range1 is present in range2. Can we compare 2 ranges in Python??

More Info--These ranges are being used to check ports .i.e range2 contains authorized(fixed and pre-define) ports and range1 is changing at run time

1
  • 3
    you can simply do if minR1 > minR2 and maxR1< maxR2 right? Commented Jan 4, 2022 at 13:36

1 Answer 1

5

You can convert those 2 lists in sets and then check if the first is contained in the other like this:

set1 = set(range(80, 90))
set2 = set(range(0, 360))
is_subset = set1.issubset(set2)
print(is_subset)
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.