Exploring Bioinformatics with Python

Converting lists of strings to strings

Since we represent sequences as both strings and as lists of length-one strings, it is useful to be able to convert between the two forms. We convert lists to strings using the string.join procedure, which requires the string library.

>>> import string
>>> string.join(['A', 'G', 'C', 'G', 'C', 'A', 'A', 'U', 'G'], '')
'AGCGCAAUG'

Note that we include a second parameter to string.join, the empty string, ''. The reason for including the empty string is left as an exercise for the reader.

See also:


This page was generated by Siteweaver on Thu Sep 10 09:37:00 2009.
The source to the page was last modified on Thu Sep 10 09:26:08 2009.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/ExBioPy/list-to-string.html.

You may wish to validate this page's HTML

Samuel A. Rebelsky
rebelsky@grinnell.edu