Skip to content

Instantly share code, notes, and snippets.

@piyonishi
Created June 18, 2013 05:17
Show Gist options
  • Save piyonishi/5802813 to your computer and use it in GitHub Desktop.
Save piyonishi/5802813 to your computer and use it in GitHub Desktop.
# インデックスつきループ
# listの場合enumerateを使う
sample_list = ['i', 'ro', 'ha', 'ni', 'ho', 'he', 'to']
for i, v in enumerate(sample_list):
print(i, v)
# dictionaryで3.xの場合itemsを使う
# iteritemsは廃止
sample_dictionary = {0:'i', 1:'ro', 2:'ha', 3:'ni', 4:'ho', 5:'he', 6:'to'}
for i, v in sample_dictionary.items():
print(i, v)
# dictionaryで2.xの場合iteritemsを使う
for i, v in sample_dictionary.iteritems():
print i, v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment