gpt4 book ai didi

python - 查找并检查列表中的项目

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:42 25 4
gpt4 key购买 nike

我的代码:

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))

返回:

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

我需要检查我的“Resource_id”是否 = 1642 并设置一个条件,如果他打印 OK,如果不打印,他就列出。

像这样:

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

最佳答案

你可以像这样做一点检查:

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)

关于python - 查找并检查列表中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32722613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com