Last active
August 29, 2015 14:00
-
-
Save st98/befafe90ce39a27cf0f9 to your computer and use it in GitHub Desktop.
'ABCD' から [(0, 'A'), (1, 'B'), (2, 'C'), (3, 'D')] を作りたい。
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
s = 'ABCD' | |
# 1 | |
i = 0 | |
result = [] | |
while True: | |
if i >= len(s): | |
break | |
result.append((i, s[i])) | |
i += 1 | |
# 2 | |
result = [] | |
for x in range(len(s)): | |
result.append((x, s[x])) | |
# 3 | |
[(x, s[x]) for x in range(len(s))] | |
# 4 | |
import itertools | |
list(zip(itertools.count(), s)) | |
# 5, 忘れてた | |
list(enumerate(s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment