Dictionaries पर iteration
जब JSON डेटा किसी dictionary में लोड हो जाता है, तो आप उसकी keys और values पर iterate करने के लिए Python के बिल्ट-इन टूल्स का उपयोग कर सकते हैं.
"nested_school_scores.json" फ़ाइल को पढ़कर raw_testing_scores वैरिएबल में एक dictionary के रूप में रखा गया है, जो इस तरह दिखती है:
{
"01M539": {
"street_address": "111 Columbia Street",
"city": "Manhattan",
"scores": {
"math": 657,
"reading": 601,
"writing": 601
}
}, ...
}
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में ETL और ELT
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
raw_testing_scores_keys = []
# Iterate through the keys of the raw_testing_scores dictionary
for school_id in raw_testing_scores.____():
# Append each key to the raw_testing_scores_keys list
raw_testing_scores_keys.append(____)
print(raw_testing_scores_keys[0:3])