我有一些列表如下:
['apple,orange,cherry', 'tomato,potato,cucumber', 'pear,grape, kiwi']
['fish,chicken,beef', 'milk,juice,tea', 'Facebook,twitter,instagram']
...
Run Code Online (Sandbox Code Playgroud)
我想在列表中拆分字符串,如下所示:
[['apple', 'orange', 'cherry'], [...], [...]]
...
Run Code Online (Sandbox Code Playgroud)
我试过了split,但没用.
你可能只需要传递一个分裂字符(即,)split.默认情况下,它仅在空格上分割.
a = ['apple,orange,cherry', 'tomato,potato,cucumber', 'pear,grape, kiwi']
b = [s.split(',') for s in a]
Run Code Online (Sandbox Code Playgroud)