slicing functionality for strings / Python suitability forbioinformatics

Terry Reedy tjreedy at udel.edu
Mon Sep 19 19:30:35 EDT 2005


"Reinhold Birkenfeld" <reinhold-birkenfeld-nospam at wolke7.net> wrote in 
message news:3p8in6F98fduU1 at individual.net...
> jbperez808 at yahoo.com wrote:
>>>>> rs='AUGCUAGACGUGGAGUAG'
>>>>> rs[12:15]='GAG'
>> Traceback (most recent call last):
>>   File "<pyshell#119>", line 1, in ?
>>     rs[12:15]='GAG'
>> TypeError: object doesn't support slice assignment
>>
>> You can't assign to a section of a sliced string in
>> Python 2.3 and there doesn't seem to be mention of this
>> as a Python 2.4 feature (don't have time to actually try
>> 2.4 yet).
>
> Strings are immutable in Python, which is why assignment to
> slices won't work.
>
> But why not use lists?
>
> rs = list('AUGC...')
> rs[12:15] = list('GAG')

Or arrays of characters: see the array module.

Terry J. Reedy






More information about the Python-list mailing list