ChamBr
ChamBr

Reputation: 21

Find and check an item within a list

My code:

for item in lista:
    trade_id = item['tradeId']
    buy_now_price = item['buyNowPrice']
    trade_state = item['tradeState']
    item_id = item['id']
    resource_id = item['resourceId']

print ('ID:' + str(item_id) + '= T: ' + str(resource_id) + ' L: '  + str(starting_bid) + ' | C ' + str(buy_now_price))

returns:

ID:85357= T: 1642 L: 900 | C 1100
ID:56639= T: 1645 L: 300 | C 350
ID:53639= T: 1642 L: 900 | C 1100
ID:10753= T: 1642 L: 900 | C 1100
ID:04575= T: 1645 L: 150 | C 5000
ID:72146= T: 1642 L: 900 | C 950

I need to check if my "Resource_id" = 1642 and put a condition where if he printa with an OK and if not he just list.

Something like this:

ID:85357= T: 1642 L: 900 | C 1100 = Ok
ID:56639= T: 1645 L: 300 | C 350
ID:53639= T: 1642 L: 900 | C 1100 = Ok
ID:10753= T: 1642 L: 900 | C 1100 = Ok
ID:04575= T: 1645 L: 150 | C 5000
ID:72146= T: 1642 L: 900 | C 950 = Ok

Upvotes: 2

Views: 39

Answers (2)

Joran Beasley
Joran Beasley

Reputation: 114088

print ('ID:' + str(item_id) + '= T: ' + str(resource_id) + ' L: '  + str(starting_bid) + ' | C ' + str(buy_now_price) + (" = OK" if int(resource_id) == 1642 else "" ))

I guess ....

Upvotes: 0

Totem
Totem

Reputation: 7369

You could do a little check like this:

output = 'ID:' + str(item_id) + '= T: ' + str(resource_id) + ' L: '  + str(starting_bid) + ' | C ' + str(buy_now_price)

if resource_id == 1642:
    output += " = OK"

print(output)

Upvotes: 1

Related Questions