In-place array modification

Peter Otten __peter__ at
Sun Jul 18 17:43:29 CEST 2004

umdehoon wrote:

> Say I have an array (Python array, not Numpy) that contains characters
> representing a DNA sequence. Something like
>>>> from array import array
>>>> s = array('c', "ATAGCTGCT")
> Now I want to calculate the reverse complement of this sequence. I could

The following does not meet your spec (it's not in-place), but might be
worth considering as well:

>>> import array, string
>>> a = array.array("c", "ATAGCTGCT")
>>> a.reverse()
>>> t = string.maketrans("ATCG", "TAGC")
>>> array.array("c", a.tostring().translate(t))
array('c', 'AGCAGCTAT')


More information about the Python-list mailing list