[Tutor] improve the code
__peter__ at web.de
Tue Nov 1 16:28:26 CET 2011
> On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel <d at davea.name> wrote:
>> On 11/01/2011 10:11 AM, lina wrote:
>> Just use the sort() method of the list object. In particular, items()
>> returns an unordered list, so it's ready to be sorted.
>> for residues, numbers in new_dictionary.items().sort():
>> That will sort such that residues are in sorted order.
> Thanks, but still something went wrong here,
> Traceback (most recent call last):
> File "fill-gap.py", line 41, in <module>
> File "fill-gap.py", line 31, in build_abetadictionary
> for residues, numbers in new_dictionary.items().sort():
> AttributeError: 'dict_items' object has no attribute 'sort'
Dave didn't realize that you are using Python 3 where items() no longer
returns a list. You need to change
as sorted() will accept an arbitrary iterable.
> I have another concerns,
> is it possible to append the output file content as a sing one,
> such as a.new is
> A 1
> B 3
> b.new is
> A 3
> B 5
> I wish the final one like:
> A 1 3
> B 3 5
> I will think about it. Thanks,
Sorry, I can't make sense of that.
More information about the Tutor