如何在字典中将元素添加到列表中?

时间:2020-04-16 16:45:39

标签: python python-3.x

我已经努力了一段时间才能完成这项工作,也许我在这里错过了一些东西。

后续代码的目的是将在CSV的每一行的第1列上找到的值添加到在第二(1)位置连续一个列表的字典中,以便将新值附加到列表中,并每次在CSV上找到相同的键都不会被覆盖(因为相同的键会被重复几次)。

csr = {} 
    with open('RawPolicy.csv', newline='') as rulemaker:
        rmatcher = csv.reader(rulemaker, delimiter=" ")

        for row in rmatcher:
            lst = []        
            csr[row[6]]=[row[0],lst.append(row[1]),row[2],row[3],row[4],row[5]]

但是我总是收到以下错误,对我来说这没有意义,因为缩进对我来说似乎还可以。

当我从for循环和“ lst.append(row [1])”部分中删除list(lst)时,脚本可以工作,但不能满足我的要求。

csr[row[6]]=[row[0],lista.append(row[1]),row[2],row[3],row[4],row[5]]

TabError: inconsistent use of tabs and spaces in indentation

1 个答案:

答案 0 :(得分:1)

您的plot <- ggplot(df.m, aes(x = Hugo_Symbol, y = value, fill=variable)) + geom_bar(stat='identity') + #geom_text(aes(label=len), vjust=1.6, color="white", size=3.5)+ #geom_text(stat = "count", aes(label = after_stat(count)), vjust = -1) theme(axis.text.x=element_text(angle = 90, vjust = 0.5)) 块缩进得太远了。应该是:

with