尚方宝剑之说
你可以使用data = """5973 4152 40 0926 53 06 3410 51 87 86 81"""result = [[int(x) for x in line.split()] for line in data.split("\n") if line]print(result)哪个产量[[59], [73, 41], [52, 40, 9], [26, 53, 6, 34], [10, 51, 87, 86, 81]]请注意,这仅适用于只有整数的情况。要进行一些错误管理,您可以使用:data = """59 some junk here73 4152 40 0926 53 06 3410 51 87 86 81"""def makeint(line): for x in line.split(): try: yield int(x) except ValueError: passresult = [[x for x in makeint(line)] for line in data.split("\n") if line]print(result)