Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Python で文字列を単一要素のリストに変換する 1 つの方法は次のとおりmy_string.split()です。ただし、文字列にスペースが含まれている場合、これは複数の要素を持つリストを返します。スペースがある場合とない場合がある文字列からリストを作成する効率的な方法は何ですか?
my_string.split()
ちょうどどうですか
l = [my_string]
文字列内の各文字をリスト内の要素に分割するつもりですか? これはどう:
>>> list("mystring") ['m', 'y', 's', 't', 'r', 'i', 'n', 'g'] >>> list("my string") ['m', 'y', ' ', 's', 't', 'r', 'i', 'n', 'g']