简化PyreResponse迭代

时间:2018-01-16 04:17:19

标签: python loops dictionary iteration

这是我的代码:

lastRow = db.child("twitter-search").order_by_key().limit_to_last(1).get(user['idToken'])

latestId = None

for row in lastRow.each():
for key, value in row.val().items():
    if key == "latest_id":
        latestId = value

它正在运作,但无论如何都要缩短它?

1 个答案:

答案 0 :(得分:0)

O(1)检查密钥是否存在,如果有,请更新latestId

latestId = None
for row in lastRow.each():
    if "latest_id" in row:
        latestId = row["latest_id"]