lists = [[] for _ in range(len(str(all_row_lists)))] for i, string in enumerate(str(all_row_lists)): nums = [int(num) for num in string.split(',')] for j, num in enumerate(nums): lists[j].append(num) lst_lisn = [] for lst in lists: lst_lisn.append(lst) print(lst_lisn) 如果有空值就跳过
时间: 2024-04-13 08:28:45 浏览: 136
lists.tar.gz_MSR list_MSR matlab_lists.tar_msr_speaker
如果要在提取数字时跳过空值,你可以使用以下代码进行修改:
```python
all_row_lists = ['11,13', '15,19', '', '23,']
lists = [[] for _ in range(len(all_row_lists))]
for i, string in enumerate(all_row_lists):
if string:
nums = [int(num) for num in string.split(',') if num.strip()]
for j, num in enumerate(nums):
lists[j].append(num)
lst_lisn = []
for lst in lists:
lst_lisn.append(lst)
print(lst_lisn)
```
这样,将会跳过空值,并且不会将空值添加到对应的列表中。输出结果将会是:
```
[[11, 15, 23], [13, 19]]
```
这样,空值对应的列表将会是空的,而其他列表将会包含对应的数字。
阅读全文