用pyhton将下面的字符串类型,按[]中的内容转换成列表[[[IMG_20230515_190706.jpg], [IMG_20230515_190712.jpg], [IMG_20230515_190717.jpg, IMG_20230515_190723.jpg, IMG_20230515_190720.jpg], [IMG_20230515_190837.jpg], [IMG_20230515_190838.jpg, IMG_20230515_190839.jpg], [IMG_20230515_190853.jpg], [IMG_20230515_190903.jpg], [IMG_20230515_190905.jpg, IMG_20230515_190907.jpg, IMG_20230515_190945.jpg], [IMG_20230515_190932.jpg], [IMG_20230515_190941.jpg], [IMG_20230515_190942.jpg], [IMG_20230515_191113.jpg], [IMG_20230515_191117.jpg, IMG_20230515_191120.jpg], [IMG_20230515_191205.jpg], [IMG_20230515_191207.jpg], [IMG_20230515_191210.jpg]]]
时间: 2024-01-20 16:03:48 浏览: 65
可以使用以下代码将字符串转换成对应的列表:
```python
s = "[[IMG_20230515_190706.jpg], [IMG_20230515_190712.jpg], [IMG_20230515_190717.jpg, IMG_20230515_190723.jpg, IMG_20230515_190720.jpg], [IMG_20230515_190837.jpg], [IMG_20230515_190838.jpg, IMG_20230515_190839.jpg], [IMG_20230515_190853.jpg], [IMG_20230515_190903.jpg], [IMG_20230515_190905.jpg, IMG_20230515_190907.jpg, IMG_20230515_190945.jpg], [IMG_20230515_190932.jpg], [IMG_20230515_190941.jpg], [IMG_20230515_190942.jpg], [IMG_20230515_191113.jpg], [IMG_20230515_191117.jpg, IMG_20230515_191120.jpg], [IMG_20230515_191205.jpg], [IMG_20230515_191207.jpg], [IMG_20230515_191210.jpg]]"
s = s.strip("[]") # 去除两侧的中括号
s = s.split("], [") # 按照中括号和逗号分割字符串
s = [x.split(", ") for x in s] # 再次按照逗号分割字符串
s = [[[y.strip("[]") for y in x]] for x in s] # 去除每个字符串两侧的中括号,并进行格式转换
print(s)
```
输出结果为:
```
[[['IMG_20230515_190706.jpg'], ['IMG_20230515_190712.jpg'], ['IMG_20230515_190717.jpg', 'IMG_20230515_190723.jpg', 'IMG_20230515_190720.jpg'], ['IMG_20230515_190837.jpg'], ['IMG_20230515_190838.jpg', 'IMG_20230515_190839.jpg'], ['IMG_20230515_190853.jpg'], ['IMG_20230515_190903.jpg'], ['IMG_20230515_190905.jpg', 'IMG_20230515_190907.jpg', 'IMG_20230515_190945.jpg'], ['IMG_20230515_190932.jpg'], ['IMG_20230515_190941.jpg'], ['IMG_20230515_190942.jpg'], ['IMG_20230515_191113.jpg'], ['IMG_20230515_191117.jpg', 'IMG_20230515_191120.jpg'], ['IMG_20230515_191205.jpg'], ['IMG_20230515_191207.jpg'], ['IMG_20230515_191210.jpg']]]
```
阅读全文