THsoul's recent timeline updates
THsoul

THsoul

V2EX member #190317, joined on 2016-09-04 11:43:44 +08:00
THsoul's recent replies
获取到 4 位数中能被 3 整除不能被 6 整除的数
list = filter(None, [i if(i%3 is 0 and i%6 is not 0) else None for i in range(1000, 10000)])

写一个返回指定长度并从元列表中剔除这些元素的方法
def push_num(list, reqlen):
count = 0
req = []
while count is not reqlen:
req.append(list[0])
del list[0]
count += 1
return req

再写一个交替判断
def list_slice(list):
req = []
req.append(push_num(list, 2))
while True:
if len(list) is 0:
return req
if len(req[-1]) is 3:
req.append(push_num(list, 2))
elif len(req[-1]) is 2:
req.append(push_num(list, 3))

最后 结合一下
list_slice( filter(None, [i if(i%3 is 0 and i%6 is not 0) else None for i in range(1000, 10000)]) )
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5368 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 08:51 · PVG 16:51 · LAX 01:51 · JFK 04:51
♥ Do have faith in what you're doing.