字符串中有列表如何把列表提取出来?
file = ['[1,2,3],[4,5,6],[7,8,9]'] data = file[0] number = [] alist = [] count = 0 i = 0 char = ['[', ',', ']'] while i < len(data): if data[i] in char: i += 1 elif count < 3: alist.append(int(data[i])) count += 1 i += 1 if count == 3: number.append(alist) alist = [] count = 0 print(number)
输出:number = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]