假设我是searching for cardType = points
,如果找到它我想知道该对象的索引位置。根据给定的示例数组,此对象的索引位置为1.下面是示例数组。
[{
cardCode = MGC;
cardId = 5720663d8944bf6710c9d894;
cardType = gift;
},
{
cardCode = MPC;
cardId = 5720663d8944bf6710c9d898;
cardType = points;
},
{
cardCode = MAC;
cardId = 5720663d8944bf6710c9d895;
cardType = advantage;
},
{
cardCode = MCC;
cardId = 5720663d8944bf6710c9d897;
cardType = cashback;
}]
答案 0 :(得分:4)
您可以使用index(where:)
。
except (KeyboardInterrupt, SystemExit):
print("Alarm stopped")