[Tutor] improve the code
d at davea.name
Fri Nov 4 03:50:04 CET 2011
On 11/03/2011 10:39 PM, lina wrote:
> On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten<__peter__ at web.de> wrote:
>> lina wrote:
> [('83ILE', 1), ('84ALA', 2), ('8SER', 0), ('9GLY', 0)]
>>>> parts = re.split(r"(\d+)",items)
> Traceback (most recent call last):
> File "<pyshell#78>", line 1, in<module>
> parts = re.split(r"(\d+)",items)
> File "/usr/lib/python3.2/re.py", line 183, in split
> return _compile(pattern, flags).split(string, maxsplit)
> TypeError: expected string or buffer
This email of Peter's is what I was referring to as regex. The re
module is for processing regular expressions. You'll have to go to
someone else for help in it, but I can point out that you can only
process one string with that line. You're handing it a whole list.
So something like:
for item in items:
parts = re.split(.....
might show you what it's doing. I suspect it'll give you a tuple with
the numeric part first, and the non-numeric part second.
More information about the Tutor