Skip to content

Instantly share code, notes, and snippets.

@tamago324
Created October 22, 2017 03:28
Show Gist options
  • Save tamago324/5a2d23f8a643928e56ac766769ae128f to your computer and use it in GitHub Desktop.
Save tamago324/5a2d23f8a643928e56ac766769ae128f to your computer and use it in GitHub Desktop.
04. 元素記号
#!/usr/bin/env python
s = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can.'
result = {}
# enumerate()でループの回数を取得する
for i, elem in enumerate(s.split(), start=1):
# 指定番号かどうか
if {i} & {1, 5, 6, 7, 8, 9, 15, 16, 19}:
result[elem[0]] = i
else:
result[elem[0:2]] = i
# 結果出力
for items in result.items():
print(items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment