Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

comparing two sets and finding equation about them python

I have two sets

list1 = {1,2,3,4,5,6,7,8,9,10}
list2 = {10,20,30,40,50,60,70,80,90,100}

I want python to see if there is a relation between each number and if the relation is the same for each number(for this example it would be the same for each number and the relation is *10)or if it is not it would print that they do not have a relation

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you use sets, you cannot define a 1-to-1 relationship, as those are unordered.

If you have lists, you could use:

list1 = [1,2,3,4,5,6,7,8,9,10]
list2 = [10,20,30,40,50,60,70,80,90,100]

ratios = [b/a for a,b in zip(list1, list2)]

Output: [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]

Or using a set comprehension:

S = {round(b/a, 3) for a,b in zip(list1, list2)}
# {10.0}

# check there is only one possibility
if len(S) != 1:
    print('there is not a unique ratio')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading