How to remove one specific element from a list
本问题已经有最佳答案,请猛点这里访问。
我的变量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [{'distance': 1.9999, 'breakEvenDistance': 1.9329, 'max': 0.0010342833053929787}, {'distance': 1.9251, 'breakEvenDistance': 2.0669999999999997, 'max': 0.0011183923895419084, 'min': 0.0010342833053929787}, {'distance': 1.8802, 'breakEvenDistance': 1.6758, 'max': 0.0011927892918825562, 'min': 0.0011183923895419084}, {'distance': 1.8802, 'breakEvenDistance': 1.5956, 'max': 0.0012522046577102665, 'min': 0.0011927892918825562}] |
我需要的是删除我列表中的最后一个
1 2 | del dict_[-1]['max'] print(dict_) |
输出:
1 2 3 4 5 6 7 8 9 | [ {'distance': 1.9999, 'breakEvenDistance': 1.9329, 'max': 0.0010342833053929787}, {'distance': 1.9251, 'breakEvenDistance': 2.0669999999999997, 'max': 0.0011183923895419084, 'min': 0.0010342833053929787}, {'distance': 1.8802, 'breakEvenDistance': 1.6758, 'max': 0.0011927892918825562, 'min': 0.0011183923895419084}, {'distance': 1.8802, 'breakEvenDistance': 1.5956, 'min': 0.0011927892918825562} ] |