回答編集履歴
2
edit
answer
CHANGED
@@ -19,4 +19,12 @@
|
|
19
19
|
|
20
20
|
get_word_count('word1', 'cat1') # OK
|
21
21
|
get_word_count('word1', '') # NG
|
22
|
+
```
|
23
|
+
|
24
|
+
---
|
25
|
+
|
26
|
+
ついでに、`word_dict = {'cat1':{'word1':1}}`と対応するように、デフォルトはリストではなく辞書を与える方がロジックが正しいです。
|
27
|
+
|
28
|
+
```python
|
29
|
+
words = word_dict.get(category, {})
|
22
30
|
```
|
1
edit
answer
CHANGED
@@ -4,4 +4,19 @@
|
|
4
4
|
|
5
5
|
```python
|
6
6
|
words = word_dict.get(category, [])
|
7
|
+
```
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
```python
|
12
|
+
word_dict = {'cat1':{'word1':1}}
|
13
|
+
def get_word_count(word, category):
|
14
|
+
words = word_dict.get(category,[])
|
15
|
+
if word in words:
|
16
|
+
print('OK')
|
17
|
+
else:
|
18
|
+
print('NG')
|
19
|
+
|
20
|
+
get_word_count('word1', 'cat1') # OK
|
21
|
+
get_word_count('word1', '') # NG
|
7
22
|
```
|