• 内包表記内の定数宣言に for ループを使用
1
2
3
for i in range(10):
    x = "variable"
    do(i, x)

から

1
[do(i, x) for i in range(10) for x in ["variable"]]
  • import 文は __import__(package_name) で代用
1
import sys

から

1
sys = __import__("sys")
  • 積極的な内包表記の活用
1
2
3
4
for i in range(10):
    for j in range(10):
        for k in range(10):
            vector(i, j, k)

から

1
[vector(i, j, k) for i in range(10) for j in range(10) for k in range(10)]

以上をまとめて

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008&lang=jp の例

1
[print(sum([int(a + b + c + d == int(x)) for a in range(10) for b in range(10) for c in range(10) for d in range(10)])) for sys in [__import__("sys")] for x in sys.stdin]