# \[課程討論\] Day 9 - Beginner - Dictionaries, Nesting and the Secret Auction

**URL:** https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071
**Category:** Py基礎組
**Tags:** 上課筆記
**Created:** [2021年三月30日 10:36 UTC](https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071 "2021-03-30T10:36:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Laurence](https://vip.studycamp.tw/user_avatar/vip.studycamp.tw/laurence/32/5523_2.png) [@Laurence](https://vip.studycamp.tw/u/Laurence)
#### Post date: [2021年三月30日 10:36 UTC](https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071/1 "2021-03-30T10:36:56Z")

</div>

Py基礎組，將於2021/4/4 PM 9:00，進行Day 9課程討論。  
相關資訊，將更新於此。

---

<div class="post-metadata">

### Author: ![Laurence](https://vip.studycamp.tw/user_avatar/vip.studycamp.tw/laurence/32/5523_2.png) [@Laurence](https://vip.studycamp.tw/u/Laurence)
#### Post date: [2021年三月30日 10:52 UTC](https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071/2 "2021-03-30T10:52:12Z")

</div>

目前，在學習9-89的經歷。  
對於key，應不應該，用單或雙引號包起來，有一點疑惑。  
因為老師在影片中(07:25)，提到key用int的型態呈現。

Tim googled到下面這個連結，看了一下，似乎是這樣子。  
但不是很了解hashable真正的意思是什麼?  
Are quoted dictionary keys an absolute must? [closed]

> <https://stackoverflow.com/questions/26790920/are-quoted-dictionary-keys-an-absolute-must>

雖然，key可以用任意一個資料型態來呈現。  
但似乎不是一個常見的用法，易混淆。

```auto
a = {
 "str": "123",
 "int": 123,
 "float": 1.23,
 "bool": True
}

b = {
 999: "123",
 988: 123,
 977: 1.23,
 966: True
}

c = {
 9.99: "123",
 9.88: 123,
 9.77: 1.23,
 9.66: True
}

d = {
 True: "123",
 False: 123,
}

print(a)
print(b)
print(c)
print(d)

```

```auto
{'str': '123', 'int': 123, 'float': 1.23, 'bool': True}
{999: '123', 988: 123, 977: 1.23, 966: True}
{9.99: '123', 9.88: 123, 9.77: 1.23, 9.66: True}
{True: '123', False: 123}
```

---

<div class="post-metadata">

### Author: ![Laurence](https://vip.studycamp.tw/user_avatar/vip.studycamp.tw/laurence/32/5523_2.png) [@Laurence](https://vip.studycamp.tw/u/Laurence)
#### Post date: [2021年四月4日 14:06 UTC](https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071/3 "2021-04-04T14:06:21Z")

</div>

Day 9，課程筆記，分享給有需要的人。  
如果，內容有錯誤，或是有想補充的，歡迎在下方回覆。  
謝謝。

[9-89.pdf](https://vip.studycamp.tw/uploads/short-url/llrEFpqT0Vu1IJaDeC1Y98c7OLN.pdf) (414.2 KB)  
[9-91.pdf](https://vip.studycamp.tw/uploads/short-url/4ZEy2C7EBHjzW5rxsP66RDaPIaK.pdf) (206.1 KB)

---

<div class="post-metadata">

### Author: ![Laurence](https://vip.studycamp.tw/user_avatar/vip.studycamp.tw/laurence/32/5523_2.png) [@Laurence](https://vip.studycamp.tw/u/Laurence)
#### Post date: [2021年四月4日 14:11 UTC](https://vip.studycamp.tw/t/%E8%AA%B2%E7%A8%8B%E8%A8%8E%E8%AB%96-day-9-beginner-dictionaries-nesting-and-the-secret-auction/1071/4 "2021-04-04T14:11:44Z")

</div>

Tim於課程討論中提出一個問題: 我們可不可以loop through dictionary，直接就帶出value?  
Googled by Google.

How to Iterate Through a Dictionary in Python

> **[How to Iterate Through a Dictionary in Python – Real Python](https://realpython.com/iterate-through-dictionary-python/#iterating-through-values)**
>
> In this step-by-step tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data structure, and you'll be able to solve a wide variety of programming problems by iterating through them.
