Re: [Tutor] improve the code

2011-11-04 Thread Peter Otten
lina wrote: > On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten <__pete...@web.de> wrote: >> lina wrote: >> sorted(new_dictionary.items()) >>> >>> Thanks, it works, but there is still a minor question, >>> >>> can I sort based on the general numerical value? >>> >>> namely not: >>> : >>> : >>> 83I

Re: [Tutor] improve the code

2011-11-03 Thread Peter Camilleri
Not sure if that is what you are after since you are calling re.split() using items when Peter was using re.split() on a single item within items so instead of this parts = re.split(r"(\d+)", str(items)) try specifying just one item, like this parts = re.split(r"(\d+)", items[0]) On Fri, Nov 4, 2

Re: [Tutor] improve the code

2011-11-03 Thread Dave Angel
On 11/03/2011 10:39 PM, lina wrote: On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten<__pete...@web.de> wrote: lina wrote: items [('83ILE', 1), ('84ALA', 2), ('8SER', 0), ('9GLY', 0)] parts = re.split(r"(\d+)",items) Traceback (most recent call last): File "", line 1, in parts = re.s

Re: [Tutor] improve the code

2011-11-03 Thread lina
On Fri, Nov 4, 2011 at 10:39 AM, lina wrote: > On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten <__pete...@web.de> wrote: >> lina wrote: >> sorted(new_dictionary.items()) >>> >>> Thanks, it works, but there is still a minor question, >>> >>> can I sort based on the general numerical value? >>> >>

Re: [Tutor] improve the code

2011-11-03 Thread lina
On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >>> sorted(new_dictionary.items()) >> >> Thanks, it works, but there is still a minor question, >> >> can I sort based on the general numerical value? >> >> namely not: >> : >> : >> 83ILE 1 >> 84ALA 2 >> 8SER 0 >

Re: [Tutor] improve the code

2011-11-02 Thread Alan Gauld
On 02/11/11 16:58, Dave Angel wrote: sorted(results) ['10B', '1A', '2C', '3D'] as [ '1A', '2C', '3D','10B'] Essence of the answer is you can supply a key=myfunc argument to sorted(). Then it's up to you what you put in that function. It sounds like you want to convert any leading digits to

Re: [Tutor] improve the code

2011-11-02 Thread Dave Angel
On 11/02/2011 11:54 AM, lina wrote: Regard the sorted(), I still have a question, how to sort something like results ['1A', '10B', '2C', '3D'] sorted(results) ['10B', '1A', '2C', '3D'] as [ '1A', '2C', '3D','10B'] Thanks, mainly based on their digital value. Peter answered essential

Re: [Tutor] improve the code

2011-11-02 Thread lina
Regard the sorted(), I still have a question, how to sort something like >>> results ['1A', '10B', '2C', '3D'] >>> sorted(results) ['10B', '1A', '2C', '3D'] as [ '1A', '2C', '3D','10B'] Thanks, mainly based on their digital value. ___ Tutor maill

Re: [Tutor] improve the code

2011-11-02 Thread lina
On Tue, Nov 1, 2011 at 11:56 PM, Dave Angel wrote: > On 11/01/2011 11:11 AM, lina wrote: >> >> On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel  wrote: >>> >>> On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have

Re: [Tutor] improve the code

2011-11-01 Thread Alan Gauld
On 01/11/11 14:33, Dave Angel 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(): I don't think this would work since sort works in place. You would need to

Re: [Tutor] improve the code

2011-11-01 Thread Peter Otten
lina wrote: >> sorted(new_dictionary.items()) > > Thanks, it works, but there is still a minor question, > > can I sort based on the general numerical value? > > namely not: > : > : > 83ILE 1 > 84ALA 2 > 8SER 0 > 9GLY 0 > : > : > > rather 8 9 ...83 84, > > Thanks, You need a custom key funct

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 11:11 AM, lina wrote: On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel wrote: On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFILEEXT=".new"

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 11:11 AM, lina wrote: On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel wrote: On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFILEEXT=".new"

Re: [Tutor] improve the code

2011-11-01 Thread lina
On Tue, Nov 1, 2011 at 11:28 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >> On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel 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 r

Re: [Tutor] improve the code

2011-11-01 Thread Peter Otten
lina wrote: > On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel 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()

Re: [Tutor] improve the code

2011-11-01 Thread lina
On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel wrote: > On 11/01/2011 10:11 AM, lina wrote: >> >> Hi, >> >> The following code (luckily) partial achieved what I wanted, but I >> still have few questions: >> >> >> #!/usr/bin/python3 >> >> import os.path >> >> INFILEEXT=".txt" >> OUTFILEEXT=".new" >> D

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFILEEXT=".new" DICTIONARYFILE="dictionary.pdb" orig_dictionary={} new_dictionary={} abetaABresidues={} d

[Tutor] improve the code

2011-11-01 Thread lina
Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFILEEXT=".new" DICTIONARYFILE="dictionary.pdb" orig_dictionary={} new_dictionary={} abetaABresidues={} def processonefiledata(infilename):