slicing functionality for strings / Python suitability for bioinformatics
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Mon Sep 19 15:43:34 EDT 2005
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')
Reinhold
More information about the Python-list
mailing list