python 2.7 - 'list' object has no attribute 'items' -
working on ubuntu 12.04, python 2.7 have error 'list' object has no attribute 'items' when call print_to_screen function. explain me please how manage dictionary created?
class median_uniq: def init(self): self.median_number_list = []
def print_to_screen(self, words_dict, is_reverse = false): words = words_dict.items() words.sort(key = lambda(a,b):(a,b), reverse = is_reverse) print("[words tweeted: %d]" % len(words)).center(60,"=") print("%-25s | %25s" % ("words", "count")) print banner w, c in words: print("%-25s | %25d" % (w, c)) def median_number(self, file_name): file_object = open(file_name, "r") number_word_list = [] line in file_object: unique_words_per_tweet = sorted(set(line.rstrip().split(" "))) number_word_list.append(len(counter((unique_words_per_tweet)))) self.median_number_list.append(numpy.median(numpy.array(number_word_list))) print self.median_number_list return self.median_number_list to call function, this:
med = median_uniq() med_list = med.median_number(input_file)
med.print_to_screen(med_list, is_reverse = false)
on command line knowing input_file .txt file. thanks
i have seen similar post, don't understand. explanation words helpful. thanks
"words_dict" in code list, attempt use python dictionary method (items())
i need working example able propose customized solution.
Comments
Post a Comment