Python-如何更新列表列表中的列表

时间:2019-03-08 17:47:58

标签: python list nested sublist

我实际上是在尝试动态地执行此操作,但是现在我只是希望得到一个静态示例,因为到目前为止我发现的代码段似乎不适用于此嵌套很深的列表(或者我我对如何应用语法有误解。

从静态的角度来看,我试图更新“运行者”子列表的“运行者”子列表(该子列表随后成为market_book的一部分,并最终成为market_books的一部分),所以我认为这会起作用: / p>

market_books[0].runners[0].x = 'test'
    setattr(market_books[0].runners[0], 'y', 'test2')
    print(market_books[0].runners[0].x, market_books[0].runners[0].y)
    print(market_books[0].json())

现在,第一个打印完全按照预期显示(即显示测试test2),但是当我尝试向上打印下一个级别时,它尚未更新,因此我认为我实际上并未对其进行更新,而仅仅是为子列表分配一个值。

完整的数据集如下:

{"marketId":"1.130856098","totalAvailable":null,"isMarketDataDelayed":null,"lastMatchTime":null,"betDelay":0,"version":2576584033,"complete":true,"runnersVoidable":false,"totalMatched":null,"status":"OPEN","bspReconciled":false,"crossMatching":false,"inplay":false,"numberOfWinners":1,"numberOfRunners":10,"numberOfActiveRunners":8,"runners":[{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":2.8,"size":4},{"price":2.78,"size":20},{"price":2.76,"size":22}],"availableToLay":[{"price":2.82,"size":11.94},{"price":2.84,"size":9.45},{"price":2.86,"size":66.97}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832765},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":18.5,"size":2},{"price":18,"size":5},{"price":17.5,"size":2.7}],"availableToLay":[{"price":19.5,"size":2.44},{"price":20,"size":10},{"price":21,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832767},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":12.5,"size":1.27},{"price":12,"size":14.96},{"price":11.5,"size":39.62}],"availableToLay":[{"price":15.5,"size":2},{"price":16,"size":15.18},{"price":16.5,"size":3.26}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832766},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":26,"size":1},{"price":25,"size":4},{"price":24,"size":2}],"availableToLay":[{"price":30,"size":2.22},{"price":32,"size":2},{"price":34,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832769},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":15,"size":4},{"price":14.5,"size":3},{"price":14,"size":5.77}],"availableToLay":[{"price":17,"size":2},{"price":17.5,"size":2},{"price":18,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832768},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":4.9,"size":51.43},{"price":4.8,"size":66.63},{"price":4.7,"size":43.31}],"availableToLay":[{"price":5,"size":108.94},{"price":5.1,"size":20},{"price":5.2,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832771},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":20,"size":6},{"price":19.5,"size":2},{"price":19,"size":2}],"availableToLay":[{"price":22,"size":2},{"price":23,"size":2},{"price":24,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832770},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":6.2,"size":8.04},{"price":6,"size":80.47},{"price":5.9,"size":2}],"availableToLay":[{"price":6.4,"size":69.24},{"price":6.6,"size":46},{"price":6.8,"size":102.33}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":10064909}],"publishTime":1552066850090,"priceLadderDefinition":{"type":"CLASSIC"},"keyLineDescription":null,"marketDefinition":{"bspMarket":false,"turnInPlayEnabled":false,"persistenceEnabled":false,"marketBaseRate":5,"eventId":"28180290","eventTypeId":"2378961","numberOfWinners":1,"bettingType":"ODDS","marketType":"NONSPORT","marketTime":"2019-03-29T00:00:00.000Z","suspendTime":"2019-03-29T00:00:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":false,"runnersVoidable":false,"numberOfActiveRunners":8,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":10064909},{"status":"ACTIVE","sortPriority":2,"id":12832765},{"status":"ACTIVE","sortPriority":3,"id":12832766},{"status":"ACTIVE","sortPriority":4,"id":12832767},{"status":"ACTIVE","sortPriority":5,"id":12832768},{"status":"ACTIVE","sortPriority":6,"id":12832770},{"status":"ACTIVE","sortPriority":7,"id":12832769},{"status":"ACTIVE","sortPriority":8,"id":12832771},{"status":"LOSER","sortPriority":9,"id":10317013},{"status":"LOSER","sortPriority":10,"id":10317010}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe\/London","openDate":"2019-03-29T00:00:00.000Z","version":2576584033,"priceLadderDefinition":{"type":"CLASSIC"}}}

我有我使用的动态代码(例如,两个for循环,但是为了避免混淆,如果有人愿意帮助静态语法,那么我将尝试将其自己应用于动态代码,否则我有点想两种解决方案!

0 个答案:

没有答案