回答編集履歴

1

スマートな方法を追記

2019/03/07 09:06

投稿

YouheiSakurai
YouheiSakurai

スコア6142

test CHANGED
@@ -21,3 +21,29 @@
21
21
  names = [name.translate(table) for name in names] # "...".translate(...)で変換
22
22
 
23
23
  ```
24
+
25
+
26
+
27
+ # 追記(もうちょっとスマートな方法)
28
+
29
+
30
+
31
+ ```python
32
+
33
+ from string import ascii_letters
34
+
35
+ from string import digits
36
+
37
+
38
+
39
+ han = ascii_letters + digits
40
+
41
+ table = {c + 65248: c for c in map(ord, han)}
42
+
43
+
44
+
45
+ names = ['T','t','1']
46
+
47
+ names = [name.translate(table) for name in names] # "...".translate(...)で変換
48
+
49
+ ```