AttributeError: 'list' object has no attribute 'keys'

2020-09-17 09:59:15 浏览数 (1)

代码语言:javascript复制
#encoding=utf-8
import os


result = {}
if os.path.exists("test.txt"):
    day_file = open("test.txt").read()
    day_file_list = day_file.split(" ")

    for i in day_file_list:
                #   print "i: s"   str(i)   "e"
        if i == "#" or " ":
            day_file_list.remove(i)
                        #continue
            if i not in result:
                result[i] = 1  
            else:
                result[i] = result[i]   1
                #   print "result i: "   str(result[i])

result = sorted(result.items(), key = lambda item: item[1], reverse=True)


for k in result.keys():
    print result[k]

解决方案:

代码语言:javascript复制
for i in result:
    print i

0 人点赞