首页 > 解决方案 > 从列表中删除括号和引号

问题描述

filter_col下面的列表给了我这样的列表:

['RP026_IP_1_S9_L001_R1_001']
['RP026_IP_2_S10_L001_R1_001']
['RP026_IP_3_S11_L001_R1_001']
['RP026_IP_4_S12_L001_R1_001']

如何删除括号并使其更像这样:

RP026_IP_1_S9_L001_R1_001
RP026_IP_2_S10_L001_R1_001
RP026_IP_3_S11_L001_R1_001
RP026_IP_4_S12_L001_R1_001

这就是我列出清单的方式:

 treated_sample = ["RP026_IP_1_S9_L001_R1_001",
                          "RP026_IP_2_S10_L001_R1_001",
                          "RP026_IP_3_S11_L001_R1_001",
                          "RP026_IP_4_S12_L001_R1_001"]

for i in treated_sample:

    filter_col.append([col for col in df if col.startswith(i)])

标签: python

解决方案


例如,如果它在一个变量名

你可以做 :

a.replace("['", "").replace("']")


推荐阅读