访问和更改嵌套dict/list数据集中的数据Python 2.7+;

访问和更改嵌套dict/list数据集中的数据Python 2.7+;,python,list,python-2.7,dictionary,nested,Python,List,Python 2.7,Dictionary,Nested,我需要一些关于访问和更改数据集中某些值的指导。我使用的是Strava API,所以它的自行车数据。我有一个字典列表,其中包含一个字符串作为键,一个列表作为值: [{'ride_name_one':[1.3,7.5,8.2,4.8]},{'ride_name_2:'[4.7,6.8,8.9,4.3]}] 我必须将这些值中的每一个从m/s转换为km/h,并将其保存回该列表。我如何深入到这些列表以更新它们?我猜是这样的: streamsTest[0]['ride\u name\u one'] 除了不

我需要一些关于访问和更改数据集中某些值的指导。我使用的是Strava API,所以它的自行车数据。我有一个字典列表,其中包含一个字符串作为键,一个列表作为值:

[{'ride_name_one':[1.3,7.5,8.2,4.8]},{'ride_name_2:'[4.7,6.8,8.9,4.3]}]
我必须将这些值中的每一个从m/s转换为km/h,并将其保存回该列表。我如何深入到这些列表以更新它们?我猜是这样的:

streamsTest[0]['ride\u name\u one']

除了不确定如何使“骑乘”动态化之外

有没有更好的转换点

以下是我目前的代码:

athleteID = [xxxxxxxx]
activityIDs = [xxxxxxxxx,xxxxxxxxx]

def getSpeeds(cIDs,aIDs):

    print cIDs
    print aIDs

    streamsTest = []

    for i in aIDs:
        aID = i
        types = ['velocity_smooth']
        streams = client.get_activity_streams(aID, types=types, resolution='low')
        activity = client.get_activity(aID)

        if 'velocity_smooth' in streams.keys():
            actName = activity.name 
            raw = streams['velocity_smooth'].data
            streamsTest.append({actName:raw})   
        else: 
            print "velocity_smooth is not available"

    print streamsTest
    #[{'key':[1,2,3,4]},{'key:'[1,2,3,4]}]
    ### do m/s to km/h conversion on nested list data


getSpeeds(athleteID,activityIDs)

找到了一种方法,如果有更好的方法,请随意评论

athleteID = [xxxxxxx]
activityIDs = [xxxxxxxxx,xxxxxxxxx]

def getSpeeds(cIDs,aIDs):

    streamsDicts = []
    streamsFinal = []

    for i in aIDs:
        aID = i
        types = ['velocity_smooth']
        streams = client.get_activity_streams(aID, types=types, resolution='low')
        activity = client.get_activity(aID) 
        if 'velocity_smooth' in streams.keys():
            actName = activity.name 
            raw = streams['velocity_smooth'].data
            streamsDicts.append({actName:raw[1:]})  
        else: 
            print "velocity_smooth is not available"

    for i in streamsDicts:
        for key, value in i.iteritems():
            value = [round((x * 3600) / 1000,2) for x in value]
            streamsFinal.append({key:value})

    print streamsFinal

getSpeeds(athleteID,activityIDs)