diff --git a/src/calibre/ebooks/rtf2xml/paragraph_def.py b/src/calibre/ebooks/rtf2xml/paragraph_def.py index 82962fe9ea..0812e15776 100755 --- a/src/calibre/ebooks/rtf2xml/paragraph_def.py +++ b/src/calibre/ebooks/rtf2xml/paragraph_def.py @@ -608,12 +608,10 @@ if another paragraph_def is found, the state changes to collect_tokens. # when determining uniqueness for a style, ingorne these values, since # they don't tell us if the style is unique ignore_values = ['style-num', 'nest-level', 'in-table'] - keys = self.__att_val_dict.keys() - keys.sort() - for key in keys: - if key in ignore_values: + for k, v in self.__att_val_dict.items(): + if k in ignore_values: continue - my_string += '%s:%s' % (key, self.__att_val_dict[key]) + my_string += '%s:%s' % (k, v) if my_string in self.__style_num_strings: num = self.__style_num_strings.index(my_string) num += 1 # since indexing starts at zero, rather than 1 @@ -637,12 +635,9 @@ if another paragraph_def is found, the state changes to collect_tokens. the_value = self.__att_val_dict['tabs'] # the_value = the_value[:-1] style_string += ('<%s>%s' % ('tabs', the_value)) - keys = self.__att_val_dict.keys() - keys.sort() - for key in keys: - if key != 'name' and key !='style-num' and key != 'in-table'\ - and key not in tabs_list: - style_string += ('<%s>%s' % (key, self.__att_val_dict[key])) + for k, v in self.__att_val_dict.items(): + if k not in ['name', 'style-num', 'in-table'] + tabs_list: + style_string += ('<%s>%s' % (k, v)) style_string += '\n' self.__body_style_strings.append(style_string) @@ -690,11 +685,9 @@ if another paragraph_def is found, the state changes to collect_tokens. the_value = self.__att_val_dict['tabs'] # the_value = the_value[:-1] self.__write_obj.write('<%s>%s' % ('tabs', the_value)) - keys = self.__att_val_dict.keys() - keys.sort() + keys = sorted(self.__att_val_dict.keys()) for key in keys: - if key != 'name' and key !='style-num' and key != 'in-table'\ - and key not in tabs_list: + if key not in ['name', 'style-num', 'in-table'] + tabs_list: self.__write_obj.write('<%s>%s' % (key, self.__att_val_dict[key])) self.__write_obj.write('\n') self.__write_obj.write(self.__start2_marker)