通过'\ t'拆分在python中拆分列表元素

时间:2014-01-10 21:04:08

标签: python

如果我有一个如下所示的列表元素。如何通过按\ t字符拆分来创建包含多个元素的列表? ['county_id\temp_2010\temp_2020\temp_2030\temp_2040\thhld_2010\thhld_2020\thhld_2030\thhld_2040\tmf_2010\tmf_2020\tmf_2030\tmf_2040\tpop_2010\tpop_2020\tpop_2030\tpop_2040\tdu_2010\tdu_2020\tdu_2030\tdu_2040\tsf_2010\tsf_2020\tsf_2030\tsf_2040']

1 个答案:

答案 0 :(得分:3)

>>> mylist = ['county_id\temp_2010\temp_2020\temp_2030\temp_2040\thhld_2010\thhld_2020\thhld_2030\thhld_2040\tmf_2010\tmf_2020\tmf_2030\tmf_2040\tpop_2010\tpop_2020\tpop_2030\tpop_2040\tdu_2010\tdu_2020\tdu_2030\tdu_2040\tsf_2010\tsf_2020\tsf_2030\tsf_2040']
>>> splitlist = mylist[0].split("\t")
>>> splitlist
['county_id', 'emp_2010', 'emp_2020', 'emp_2030', 'emp_2040', 'hhld_2010', 'hhld_2020', 'hhld_2030', 'hhld_2040', 'mf_2010', 'mf_2020', 'mf_2030', 'mf_2040', 'pop_2010', 'pop_2020', 'pop_2030', 'pop_2040', 'du_2010', 'du_2020', 'du_2030', 'du_2040', 'sf_2010', 'sf_2020', 'sf_2030', 'sf_2040']

应该做的伎俩...