我有以下数据..你可以在开头看到两行之间的空格,而在其他一些行之间没有空格:
Report Area
Total Population
Total Land Area
(Square Miles)
Population Density
(Per Square Mile)
Report Area 37,325,068 155,738.02 239.67
Alameda County, CA 1,515,136 738.82 2,050.75
Alpine County, CA 1,197 738.13 1.62
Amador County, CA 37,764 594.43 63.53
Butte County, CA 220,101 1,636.03 134.53
Calaveras County, CA 45,507 1,019.74 44.63
Colusa County, CA 21,329 1,150.43 18.54
我需要最终输出:
Report Area Total Population Total Land Area(Square Miles) Population Density(Per Square Mile)
Report Area 37,325,068 155,738.02 239.67
Alameda County, CA 1,515,136 738.82 2,050.75
Alpine County, CA 1,197 738.13 1.62
Amador County, CA 37,764 594.43 63.53
Butte County, CA 220,101 1,636.03 134.53
Calaveras County, CA 45,507 1,019.74 44.63
Colusa County, CA 21,329 1,150.43 18.54
我试过在f中使用output =“”.join(line.strip()for line)
但它不能按我的需要工作.
这是我的输出:
Report Area Total Population Total Land Area (Square Miles) Population Density (Per Square Mile) Report Area 37,325,068 155,738.02 239.67 Alameda County, CA 1,515,136 738.82 2,050.75 Alpine County, CA 1,197 738.13 1.62 Amador County, CA 37,764 594.43 63.53
所有行都在一行..