小编D. *_* K.的帖子

删除字典中的\n

我在我的程序中删除\n有问题这里是代码

with open(filename) as f:
    for line in f.readlines():
        parent, child = line.split(",")
            parent.strip()
            child.strip()
            children[child].append(parent)
Run Code Online (Sandbox Code Playgroud)

尝试使用.rstrip和其他变种,但它对我没有任何作用,这是我得到的结果

{'Patricia\n': ['Mary'], 'Lisa\n': ['Mary']} 
Run Code Online (Sandbox Code Playgroud)

问题是,当我打电话给孩子["Patricia"]我得到[],因为它只识别孩子["Patricia \n"]

python whitespace dictionary python-3.x

6
推荐指数
2
解决办法
113
查看次数

标签 统计

dictionary ×1

python ×1

python-3.x ×1

whitespace ×1