去除一维list中的空格
list1 = ['122','2333 ','3444 ',' ','422',' ',' ','54',' ']
list1=[x.strip() for x in list1 if x.strip() != '']
print(list1)
结果:['122', '2333', '3444', '422', '54']
去除二维list中的空格
list2= [[" 10.102.10.11 ", "kjhk "],[" dsdsf "," kljdi "]]
result = [[s.strip() for s in inner] for inner in list2]
print(result)
结果:[['10.102.10.11', 'kjhk'], ['dsdsf', 'kljdi']]