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

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.

主站蜘蛛池模板: 安福县| 东乡县| 新兴县| 政和县| 昌乐县| 宣汉县| 朝阳区| 大洼县| 邳州市| 彩票| 沧源| 定西市| 安西县| 舞钢市| 龙岩市| 合川市| 响水县| 同心县| 潞西市| 三门县| 弥勒县| 峨山| 宁津县| 阳泉市| 巫溪县| 南汇区| 奉节县| 达孜县| 昌江| 民县| 河北省| 高邮市| 胶南市| 惠来县| 剑川县| 惠水县| 彰武县| 灵璧县| 石首市| 佛山市| 新疆|