将整数从数字以单调递增的顺序1
写入的pythonic和有效的方法是什么?10**6
例如:
(1,2,3,4,5,6,7,8,9,10,11,20,21,22,30,31,32,33,...)
这完成了工作,但看起来很丑陋。
nums = [10**0*k6 for k6 in range(1,10)] +
[10**1*k5 + 10**0*k6 for k5 in range(1,10) for k6 in range(k5+1)] +
[10**2*k4 + 10**1*k5 + 10**0*k6
for k4 in range(1,10) for k5 in range(k4+1) for k6 in range(k5+1)] +
[10**3*k3 + 10**2*k4 + 10**1*k5 + 10**0*k6
for k3 in range(1,10) for k4 in range(k3+1) for k5 in range(k4+1) for k6 in range(k5+1)] +
[10**4*k2 + 10**3*k3 + 10**2*k4 + 10**1*k5 + 10**0*k6
for k2 in range(1,10) for k3 in range(k2+1) for k4 in range(k3+1) for k5 in range(k4+1) for k6 in range(k5+1)] +
[10**5*k1 + 10**4*k2 + 10**3*k3 + 10**2*k4 + 10**1*k5 + 10**0*k6
for k1 in range(1,10) for k2 in range(k1+1) for k3 in range(k2+1) for k4 in range(k3+1) for k5 in range(k4+1) for k6 in range(k5+1)]