I would like to extract the second key of every dictionary using a for loop. However, the dictionaries are nested in a list (see below). Also, notice that the second key is not always the same.
video_Ids = [
{'kind': 'youtube#playlist',
'playlistId': 'PLt1O6njsCRR-D_1jUAhJrrDZyYL6OZSGa'},
{'kind': 'youtube#playlist',
'playlistId': 'PLt1O6njsCRR_8oi7E6qnPWGQbn8NoQ6sG'},
{'kind': 'youtube#channel', 'channelId': 'UC4i5R6-IW05iiU8Vu__vppA'},
{'kind': 'youtube#video', 'videoId': 'XquM0L2WUio'},
{'kind': 'youtube#video', 'videoId': '05yrGVZ96b4'}
]
I have tried different things but none have worked so far. Here is my last attempt: deleting the first key to be left with a list containing the second keys.
for i in video_Ids:
if video_Ids["kind"] == "youtube#video":
del video_Ids[i]["kind"]
elif video_Ids[i]["kind"] == "youtube#playlist":
del video_Ids[i]["kind"]
elif video_Ids[i]["kind"] == "youtube#channel":
del video_Ids[i]["kind"]
this is the message I get:
TypeError: list indices must be integers or slices, not str
I tried my best and got stuck on this for a few days now. I really appreciate any help, Thank you.