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

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.

主站蜘蛛池模板: 比如县| 庆城县| 凤翔县| 安远县| 林周县| 宁都县| 安宁市| 东至县| 蒙自县| 琼海市| 靖江市| 屏边| 郯城县| 湘西| 盘山县| 邻水| 交口县| 青浦区| 灵石县| 泰州市| 阿拉善左旗| 庆城县| 杂多县| 隆尧县| 汉沽区| 二连浩特市| 尉氏县| 高密市| 桦川县| 云霄县| 涟水县| 武清区| 宿州市| 富阳市| 三都| 那曲县| 中牟县| 温州市| 楚雄市| 上饶市| 盖州市|