私は単純な配列をしようとしています& Pythonでの文字列変換はまだ止まっています。配列内のネストされた文字列を分割された単語に変換する方法はありますか?
data = ['one, two, three', 'apple, pineapple', 'frog, rabbit, dog, cat, horse']
そして、私はこの結果に到着したい:私はこの配列を持っている
new_data = ['one', 'two', 'three', 'apple', 'pineapple', 'frog', 'rabbit', 'dog', 'cat', 'horse']
これは私がやっているが、私は
data_to_string = ''.join(data)
new_data = re.findall(r"[\w']+", data_to_string)
を使用するたびものです
それは私にこれを与える:
['one', 'two', 'threeapple', 'pineapplefrog', 'rabbit', 'dog', 'cat', 'horse']
"threeapple"と "pineapplefrog"が分かれていないことがわかりますが、どうすればこの問題を回避できますか?
次にリスト内包表記をチェックします:) – Lindow