Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T'). 

Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structure and contains no Thymine. In RNA Thymine is replaced by another nucleic acid Uracil ('U').

Create a function which translates a given DNA string into RNA.

For example:

```
"GCAT"  =>  "GCAU"
```

The input string can be of arbitrary length - in particular, it may be empty.  All input is guaranteed to be valid, i.e. each input string will only ever consist of `'G'`, `'C'`, `'A'` and/or `'T'`.

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def dna_to_rna(dna):
	

Solutions:
def dna_to_rna(dna):
	return dna.replace('T', 'U')


dna_to_rna = lambda s: s.replace('T', 'U')


def dna_to_rna(dna):
	rna = []
	for x in dna:
		if x == 'T':
			rna.append('U')
		else:
			rna.append(x)
	return ''.join(rna)


dna_to_rna = lambda dna: dna.translate(str.maketrans('GCAT', 'GCAU'))


def dna_to_rna(mot):
	new_mot = [lettre.replace('T', 'U') for lettre in mot]
	return ''.join(new_mot)


def dna_to_rna(dna):
	res = ''
	for i in dna:
		if i == 'T':
			res += 'U'
		else:
			res += i
	return res


def dna_to_rna(dna):
	total = ''
	for i in dna:
		if i == 'T':
			total += 'U'
		else:
			total += i
	return total


def dna_to_rna(dna):
	res = ''
	for let in dna:
		if let == 'T':
			res += 'U'
		else:
			res += let
	return res


def dna_to_rna(deoxyribonucleic_acid):
	return ''.join(str([nucleic_acid_base if ord(nucleic_acid_base) is not eval('1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1') else chr(ord(nucleic_acid_base) + 1) for nucleic_acid_base in deoxyribonucleic_acid]).replace('""', '').replace(',', '').replace('[', '').replace(']', '').replace("'", '').split(' '))


def dna_to_rna(dna):
	rna_line = []
	dna_str = dna.upper()
	for a in dna_str:
		if a == 'T':
			rna_line.append('U')
		else:
			rna_line.append(a)
	result = ''.join(rna_line)
	return result


def dna_to_rna(dna):
	rna = dna.replace('T', 'U')
	return rna
print(dna_to_rna('GCAT'))


def dna_to_rna(dna):
	dna_bases = []
	for item in dna:
		dna_bases.append(str(item))
	rna_lst = []
	for item in dna_bases:
		if item == 'A' or item == 'C' or item == 'G':
			rna_lst.append(item)
		elif item == 'T':
			rna_lst.append('U')
		else:
			print('This is no dna structure')
			break
	rna = ''.join(rna_lst)
	return rna


def dna_to_rna(dna):
	if 'T' not in dna:
		return dna
	else:
		rna = dna.replace('T', 'U')
		return rna
	return


def dna_to_rna(dna):
	rna = ''
	for base in dna:
		if base != 'T':
			rna += base
		else:
			rna += 'U'
	return rna


def dna_to_rna(dna):
	rna = []
	if 'T' in dna:
		dna = dna.replace('T', 'U')
	return dna


def dna_to_rna(dna):
	res = ''
	if len(dna) == 0:
		return res
	else:
		for item in dna:
			if item == 'T':
				res += 'U'
			else:
				res += item
		return res


dnatab = 'T'
rnatab = 'U'

def dna_to_rna(dna):
	return dna.translate(dna.maketrans(dnatab, rnatab))


def dna_to_rna(dna):
	output = ''
	for i in dna:
		if i == 'T':
			output += 'U'
		else:
			output += i
	return output


def dna_to_rna(dna):
	result = []
	for i in dna:
		if i == 'T':
			result.append('U')
		else:
			result.append(i)
	return ''.join(result)


def dna_to_rna(dna):
	RNA = ''
	for letter in dna:
		if letter == 'T':
			RNA += 'U'
		else:
			RNA += letter
	return RNA


def dna_to_rna(dna):
	for t in dna:
		if t == 'T':
			dna = dna.replace('T', 'U')
	return dna


def dna_to_rna(dna):
	dna = dna.upper()
	if 'T' in dna:
		dnaList = list(dna)
		while 'T' in dnaList:
			dnaList[dnaList.index('T')] = 'U'
		rna = ''.join(dnaList)
	else:
		rna = dna
	return rna


def dna_to_rna(dna):
	if 'T' in dna:
		return dna.replace('T', 'U')
	else:
		return dna


def dna_to_rna(dna):
	rna = ''
	for i in dna:
		if i == 'T':
			rna = rna + 'U'
		else:
			rna = rna + i
	return rna


def dna_to_rna(dna):
	y = ''
	i = 0
	while i < len(dna):
		if dna[i] == 'T':
			y = y + 'U'
			i = i + 1
		else:
			y = y + dna[i]
			i = i + 1
	return y


def dna_to_rna(dna):
	new = ''
	for i in range(len(dna)):
		if dna[i] == 'T':
			new += 'U'
		else:
			new += dna[i]
	return new


def dna_to_rna(dna):
	result = ''
	for i in dna:
		if i == 'T' or '':
			i = 'U'
		result += i
	return result
print(dna_to_rna('GCAT'))


import string

def dna_to_rna(dna):
	return dna.translate(str.maketrans('GCAT', 'GCAU'))


def dna_to_rna(dna):
	rna = ''
	for ch in dna:
		if ch == 'T':
			rna += 'U'
		else:
			rna += ch
	return rna


def dna_to_rna(dna):
	s = ''
	for i in dna:
		if i == 'T':
			i = 'U'
			s = s + i
		else:
			s = s + i
	return s


def dna_to_rna(dna):
	answer = ''
	for letter in dna:
		if letter == 'T':
			answer += 'U'
		else:
			answer += letter
	return answer


def dna_to_rna(dna):
	j = ''
	for i in dna:
		if i == 'T':
			j += 'U'
		else:
			j += i
	return j


def dna_to_rna(dna):
	for T in dna:
		dna = dna.replace('T', 'U')
	return dna


def dna_to_rna(dna):
	rna = ''
	for letter in dna:
		if letter == 'T':
			rna += 'U'
		else:
			rna += letter
	return rna


def dna_to_rna(dna):
	for i in range(len(dna)):
		if dna[i] == 'T':
			dna = dna[:i] + 'U' + dna[i + 1:]
	return dna


def dna_to_rna(dna):
	rna = ''
	for base in dna:
		if base == 'T':
			rna = rna + 'U'
		elif base == 'G' or 'C' or 'A':
			rna = rna + base
		else:
			print(f'{base} is not a DNA nucleotide base')
	return rna


import pandas as pd

def dna_to_rna(dna):
	return dna.replace('T', 'U')


def dna_to_rna(dna):
	import re
	return re.sub('T', 'U', dna)


def dna_to_rna(dna):
	output = []
	answer = ''
	for i in range(len(dna)):
		output += [dna[i]]
		if output[i] == 'T':
			output[i] = 'U'
		answer += output[i]
	return answer


def dna_to_rna(dna):
	translate = {'T': 'U', 'A': 'A', 'C': 'C', 'G': 'G'}
	return ''.join(list(map(lambda x: translate[x], dna)))


def dna_to_rna(dna):
	rna = ''
	for l in dna:
		if l.upper() == 'T':
			rna += 'U'
		else:
			rna += l.upper()
	return rna


def dna_to_rna(dna):
	rna = dna.maketrans('T', 'U')
	return dna.translate(rna)


def dna_to_rna(dna):
	return ''.join(map(lambda a: 'U' if a is 'T' else a, dna))


def dna_to_rna(dna):
	t = ''
	for x in dna:
		if x == 'T':
			x = 'U'
		t += x
	return t


def dna_to_rna(dna):
	ans = ''
	for i in dna:
		if i == 'T':
			ans = ans + 'U'
		else:
			ans = ans + i
	return ans


def dna_to_rna(s):
	s1 = ''
	for i in s:
		if i == 'T':
			s1 += 'U'
		elif i == 'U':
			s1 += 'T'
		else:
			s1 += i
	return s1


s = ''

def dna_to_rna(dna):
	ddna = list(dna)
	xy = len(ddna)
	for i in range(xy):
		if ddna[i] == 'T':
			ddna[i] = 'U'
		else:
			None
	return s.join(ddna)


def dna_to_rna(dna):
	dnaList = list(dna)
	rnaList = []
	for x in dnaList:
		if x == 'T':
			rnaList.append('U')
		else:
			rnaList.append(x)
	return ''.join(rnaList)


def dna_to_rna(dna):
	rna = ''
	for nucleic_acid in dna:
		if nucleic_acid == 'T':
			rna += 'U'
		else:
			rna += nucleic_acid
	return rna


def dna_to_rna(dna):
	d = {'T': 'U'}
	return ''.join([d.get(i, i) for i in dna])


def dna_to_rna(letters):
	whatevs = letters
	return whatevs.replace('T', 'U')


def dna_to_rna(dna):
	return ''.join(('U' if char == 'T' else char for char in dna))


def dna_to_rna(dna):
	a = [i if i != 'T' else 'U' for i in dna]
	return ''.join(a)


def dna_to_rna(dna):
	for x in dna:
		if x == 'T':
			y = dna.replace('T', 'U')
			return y
	return dna


def dna_to_rna(dna):
	new = ''
	for i in dna:
		if i in ['G', 'C', 'A']:
			new += i
		elif i == 'T':
			new += 'U'
	return new


def dna_to_rna(dna):
	dna = list(dna)
	for i in range(len(dna)):
		if dna[i] == 'T':
			dna[i] = 'U'
	return ''.join(dna)


import string

def dna_to_rna(dna):
	translation = {84: 85}
	return dna.translate(translation)


def dna_to_rna(dna):
	pattern1 = 'GCAT'
	pattern2 = 'GCAU'
	translation = str.maketrans(pattern1, pattern2)
	return dna.translate(translation)


def dna_to_rna(dna):
	rna = ''
	for c in dna:
		if c == 'T':
			rna += 'U'
		else:
			rna += c
	return rna


def dna_to_rna(dna):
	ret = ''
	print(dna)
	for c in dna:
		if c == 'T':
			ret = ret + 'U'
		else:
			ret = ret + c
	print(ret)
	return ret


def dna_to_rna(dna):
	x = []
	for i in range(len(dna)):
		if dna[i] == 'T':
			x.append('U')
		else:
			x.append(dna[i])
	return ''.join(map(str, x))


import re
dnaRegex = re.compile('T')

def dna_to_rna(dna):
	return dnaRegex.sub('U', dna)