当字符串有两个连续制表符(';\t';)时,python split能否返回None?
例如,如果字符串为:当字符串有两个连续制表符(';\t';)时,python split能否返回None?,python,split,Python,Split,例如,如果字符串为:“1\t2\t3\t\t4” 它能否像这样返回列表:['1','2','3',None',4'] [x or None for x in "1\t2\t3\t\t4".split("\t")] #>>> ['1', '2', '3', None, '4'] 如果您确实想要ints,如您的示例所示: [int(x) if x else None for x in "1\t2\t3\t\t4".split("\t")] #>>> [1, 2,
“1\t2\t3\t\t4”
它能否像这样返回列表:['1','2','3',None',4']
[x or None for x in "1\t2\t3\t\t4".split("\t")]
#>>> ['1', '2', '3', None, '4']
如果您确实想要int
s,如您的示例所示:
[int(x) if x else None for x in "1\t2\t3\t\t4".split("\t")]
#>>> [1, 2, 3, None, 4]
您是在问
split
是否能做到这一点,还是在问如何做到这一点?