I've made a few assumptions here, and this is probably not the most elegant solution, but given that your matching None based on the length of space, this will work
[[(None if a.strip() == 'None' else a.strip())
for a in l.replace(' ', ' None ').split(' ') if a != ''
] for l in lst]
this is currently implemented as a list comprehension, but could easily be spread over multiple lines for readability as such
new_list = []
for l in lst:
sub_list = []
for a in l.replace(' ', ' None ').split(' '):
if a != '':
item = a.strip()
sub_list.append(None if item == 'None' else item)
new_list.append(sub_list)
either method yields the same result:
[
[
'22774080.570 7', None, '1762178.392 7', '1346501.808 8', '22774088.434 8'
],
[
'20194290.688 8', None, '-2867460.044 8', '-2213132.457 9', '20194298.629 9'
]
]
Bear in mind that any changes to the width of spaces used to define 'None' will impact the function of this implementation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…