- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 145字
- 2021-07-15 17:15:02
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.
推薦閱讀
- PWA入門與實踐
- 案例式C語言程序設計
- C#編程入門指南(上下冊)
- 少年輕松趣編程:用Scratch創作自己的小游戲
- Scratch 3.0少兒編程與邏輯思維訓練
- Mastering Kali Linux for Web Penetration Testing
- C++程序設計基礎教程
- STM32F0實戰:基于HAL庫開發
- Java Web開發詳解
- Julia for Data Science
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- 零基礎學SQL(升級版)
- Laravel Design Patterns and Best Practices
- Python人工智能項目實戰
- C#程序設計基礎與實踐