Skip to content

Commit cd032ee

Browse files
committed
midterm
1 parent 4d42ead commit cd032ee

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

midterm-7-2-2563.ipynb

+25-7
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
" f[listnum[i]] = listtext[i]\n",
3434
" else:\n",
3535
" f[listtext[i]] = listnum[i]\n",
36+
" \n",
3637
" return(f)"
3738
]
3839
},
3940
{
4041
"cell_type": "code",
41-
"execution_count": 81,
42+
"execution_count": 9,
4243
"metadata": {},
4344
"outputs": [],
4445
"source": [
@@ -47,16 +48,16 @@
4748
},
4849
{
4950
"cell_type": "code",
50-
"execution_count": 82,
51+
"execution_count": 10,
5152
"metadata": {},
5253
"outputs": [
5354
{
5455
"data": {
5556
"text/plain": [
56-
"{'apple': 1, 'banana': 2, 'orange': 3}"
57+
"{1: 'apple', 'banana': 2, 3: 'orange'}"
5758
]
5859
},
59-
"execution_count": 82,
60+
"execution_count": 10,
6061
"metadata": {},
6162
"output_type": "execute_result"
6263
}
@@ -67,16 +68,16 @@
6768
},
6869
{
6970
"cell_type": "code",
70-
"execution_count": 83,
71+
"execution_count": 8,
7172
"metadata": {},
7273
"outputs": [
7374
{
7475
"data": {
7576
"text/plain": [
76-
"{'A': 7, 'B': 1, 'C': 4, 'Zzz': 6}"
77+
"{7: 'A', 1: 'B', 'C': 4, 'Zzz': 6}"
7778
]
7879
},
79-
"execution_count": 83,
80+
"execution_count": 8,
8081
"metadata": {},
8182
"output_type": "execute_result"
8283
}
@@ -85,6 +86,23 @@
8586
"smartDict([7,1,4,6],['A','B','C','Zzz'])"
8687
]
8788
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 7,
92+
"metadata": {},
93+
"outputs": [],
94+
"source": [
95+
"## ที่ถูกต้องคือ \n",
96+
"def smartDict(listnum,listtext):\n",
97+
" out = {}\n",
98+
" for ind in range(len(listnum)):\n",
99+
" if listnum[ind] % 2 != 0:\n",
100+
" out[listnum[ind]] = listtext[ind]\n",
101+
" else:\n",
102+
" out[listtext[ind]] = listnum[ind]\n",
103+
" return out"
104+
]
105+
},
88106
{
89107
"cell_type": "markdown",
90108
"metadata": {},

0 commit comments

Comments
 (0)