If you want a function that converts the base name to its corresponding letter, you are lucky here, because it is simply the first letter of the base name.
Taking the first letter of a string is easily done by "indexing". For instance:
base = "Adenosine"
letter = base[0]
# letter should now be "A"
In a simple case like this, one would probably not bother defining a specific function, but it is possible and may look as follows:
def base2letter(base):
"""This function converts the name of a base into the corresponding letter."""
return base[0]
Now you can apply the function to every base name in your list. The usual way to do this in python is by using a "list comprehension":
letters_list = [base2letter(base) for base in bases_list]
What you have now is the list of the letters: ["A", "G", "T", "C", "T", "A", "G", "C", "T", "A", "G"]
The next step is to join them together into a string. An efficient way to do this is to use the join
method that is defined for strings. It sticks the string between the successive elements it is given: "_".join(["A", "B", "C"])
will result in "A_B_C"
. Here you want to put the letters together with nothing between them, so you have to use the empty string:
dna = "".join(letters_list)
Note that progressively building the string in a for loop by concatenating new letters one by one to the current state of the string is possible (see https://stackoverflow.com/a/47036161/1878788). This may be expected of you if python is just used to give you a general idea of how programming languages using an "imperative" style work. However, it is not efficient in python, that is why many answers did not use this technique.