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.
たとえば、文字列が次の場合:"1\t2\t3\t\t4"
"1\t2\t3\t\t4"
次のようなリストを返すことができますか?['1', '2', '3', None, '4']
['1', '2', '3', None, '4']
[x or None for x in "1\t2\t3\t\t4".split("\t")] #>>> ['1', '2', '3', None, '4']
あなたの例のように本当にしたい場合int:
int
[int(x) if x else None for x in "1\t2\t3\t\t4".split("\t")] #>>> [1, 2, 3, None, 4]