官术网_书友最值得收藏!

Iterating through entries

for ship in captains:
print (ship + ": " + captains[ship])

The output of the above code is as follows:

Let's look at a little example of iterating through the entries in a dictionary. If I want to iterate through every ship that I have in my dictionary and print out captains, I can type for ship in captains, and this will iterate through every single key in my dictionary. Then I can print out the lookup value of each ship's captain, and that's the output that I get there.

There you have it. This is basically the main data structures that you'll encounter in Python. There are some others, such as sets, but we'll not really use them in this book, so I think that's enough to get you started. Let's dive into some more Python nuances in our next section.

主站蜘蛛池模板: 文安县| 洪湖市| 赤城县| 浦江县| 浦城县| 疏附县| 泸西县| 惠东县| 长汀县| 六枝特区| 西充县| 江西省| 延安市| 兴化市| 六盘水市| 扶余县| 花垣县| 大洼县| 铜鼓县| 金门县| 台江县| 太原市| 建瓯市| 尉氏县| 钦州市| 成都市| 毕节市| 伊宁市| 南皮县| 忻州市| 额尔古纳市| 阳西县| 望谟县| 台东市| 陇西县| 西城区| 灵寿县| 定州市| 库尔勒市| 凤庆县| 马龙县|