Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 7, 2013 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/5943037 to your computer and use it in GitHub Desktop.
Save shigemk2/5943037 to your computer and use it in GitHub Desktop.
# -*- coding: euc-jp -*-"
# リストを操作するコードをループごとにインタプリタ上で処理している
# カウンタの操作もループごとにインタプリタ上で処理する必要がある
size = 10
L = []
i = 0
while i < size:
if i % 2 == 0 and i != 4:
L.append(i)
i += 1
print L # [0, 2, 6, 8]
# そこでリスト内包表記
print [i for i in range(10) if i % 2 == 0 and i != 4] # [0, 2, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment