我想分开一个句子并替换它的引号。我做了:
sentences = read_data.split('\n')
sentences_no_quotes = [sentence.replace('"', '') for sentence in sentences]
splited_sentences = [sentence.split(',') for sentence in sentences_no_quotes]
我怎样才能在一行中完成?有什么建议!谢谢你的帮助
答案 0 :(得分:1)
做到这一点,它很简单。
splited_sentences = [sentence.split(',') for sentence in
[sentence.replace('"', '') for sentence in
read_data.split('\n')]]
可能你最好使用生成器代替列表,但这超出了你的问题。