def f(n,s=""): if s[7:]:print s if n:f(n-1,s+"1") if n+len(s)<8:f(n,s+"0") map(f,range(9))