Last active
June 2, 2017 13:22
-
-
Save whosaysni/8459b73d9f96f5766b8c27ee92fe5623 to your computer and use it in GitHub Desktop.
本当は怖いジェネレータ式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from __future__ import unicode_literals | |
from itertools import chain | |
AREA_MAP = { | |
'北海道': ['北海道'], | |
'東北': ['青森県', '岩手県', '宮城県', '秋田県', '山形県', '福島県'], | |
'関東': ['茨城県', '栃木県', '群馬県', '埼玉県', '千葉県', '東京都', '神奈川県'], | |
'東海': ['岐阜県', '静岡県', '愛知県', '三重県'], | |
'甲信越': ['山梨県', '長野県', '新潟県'], | |
'北陸': ['富山県', '石川県', '福井県'], | |
'近畿': ['大阪府', '兵庫県', '京都府', '滋賀県', '奈良県', '和歌山県'], | |
'中国': ['鳥取県', '島根県', '岡山県', '広島県', '山口県'], | |
'四国': ['香川県', '徳島県', '高知県', '愛媛県'], | |
'九州': ['福岡県', '佐賀県', '長崎県', '熊本県', '大分県', '宮崎県', '鹿児島県'], | |
'沖縄': ['沖縄県'], | |
} | |
expressions = [ | |
[[(pref, area) for pref in prefs] for area, prefs in AREA_MAP.items()], | |
[((pref, area) for pref in prefs) for area, prefs in AREA_MAP.items()], | |
([(pref, area) for pref in prefs] for area, prefs in AREA_MAP.items()), | |
(((pref, area) for pref in prefs) for area, prefs in AREA_MAP.items()), | |
] | |
area = '????' | |
for i, expression in enumerate(expressions): | |
print('Pattern #{}:'.format(i + 1)) | |
for p, a in chain(*expression): | |
print('{} は {} 地方です。'.format(p, a)) | |
print('-' * 60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment