获取到 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)]) )