如何使用Python在动态创建的列表中追加字符串值?

时间:2017-11-14 21:34:17

标签: python-3.x pandas beautifulsoup

尝试使用for循环在不同列表中附加str值。以下是我的反感请帮我解决这个问题。

directors_1 = [] directors_2 = [] directors_3 = [] directors_4 = []
director = dict()

    for director_no in range(0, 4):
        if container.find_all('p')[2].find_all('a', href=True)[director_no]['href'][-11:] == 'adv_li_dr_'+str(director_no):
            director[director_no+1] = (container.find_all('p')[2].find_all('a', href=True)[director_no].text).strip()
            d = director[1]
            "directors_" + str(director_no+1).append(d) #Problem with this line
        else:
            "directors_" + str(director_no+1).append('NA')

0 个答案:

没有答案