Multidict Comparison of Two Values in Python

Asked 2 years ago, Updated 2 years ago, 416 views

I,p=multidict ({1:9, 2:4, 3:7, 4:3})
W,w = multidict ({1:3, 2:5, 3:4, 4:1})

I'd like to create a program that compares the two values of and outputs those that meet the requirements.

for in I:
    if p.values(i)<w.values(i)US>:
        print(i)

If so,

TypeError: values() takes no arguments (1given)

I don't know because it says
Where should I change it?

python data-structure

2022-09-30 22:00

1 Answers

 from gurobipy import multidict

I,p = multidict ({1:9, 2:4, 3:7, 4:3})
W,w = multidict ({1:3, 2:5, 3:4, 4:1})

for in I:
    if i in w and p[i]<w[i]:
        print(i)

#
2

Or

 from gurobipy import multidict

I,p = multidict ({1:9, 2:4, 3:7, 4:3})
W,w = multidict ({1:3, 2:5, 3:4, 4:1})

keys=[i for i in p if i in w[i]<w[i]]
print(keys)

#
[2]


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.