-2
list1 = [{'symbol': 'EOS/USD:USD-220930','type': 'limit','side': 'buy','price': 0.7,'amount': 1.0},{'symbol': 'EOS/USD:USD-220930','type': 'limit','side': 'buy','price': 0.75,'amount': 2.0}]
result = list1[0]['side'] == 'buy' or list1[1]['side'] == 'buy'

result = True

but problem occur when list1 is updated every 5 second and list of dictionary some time 1 or 0 or 5, so how can get resut = True, if any one of 'side' == 'buy' in list of dictionary.

azro
  • 53,056
  • 7
  • 34
  • 70

2 Answers2

0

Use any

values = [{'symbol': 'EOS/USD:USD-220930', 'type': 'limit', 'side': 'buy', 'price': 0.7, 'amount': 1.0},
          {'symbol': 'EOS/USD:USD-220930', 'type': 'limit', 'side': 'buy', 'price': 0.75, 'amount': 2.0}]

result = any(x['side'] == "buy" for x in values)

print(result)
azro
  • 53,056
  • 7
  • 34
  • 70
0
list1 = [{'symbol': 'EOS/USD:USD-220930', 'type': 'limit', 'side': 'buy', 'price': 0.7, 'amount': 1.0},
         {'symbol': 'EOS/USD:USD-220930', 'type': 'limit', 'side': 'buy', 'price': 0.75, 'amount': 2.0}]

result = False
for d in list1:
    if d.get('side') == 'buy':
        result = True
        break

print(result)