0

For the example I have below I am wondering if I could use an "if" statement so when a variable, that is not A,C,G, or T, is selected the resulting value is [0,0,0,0]. I understand that the version that I have below works. The problem is that I am knowing there is a much more convenient way of getting to this step. I would appreciate any help.

A = [1,0,0,0]

C = [0,1,0,0]

G = [0,0,1,0]

T = [0,0,0,1]

B = D = E = F = H = I = J = K = L = M = N = O = P = Q = R = S = U = V = W = X = Y = Z = [0,0,0,0]

print(A,C,G,T,M)

[1, 0, 0, 0] [0, 1, 0, 0] [0, 0, 1, 0] [0, 0, 0, 1] [0, 0, 0, 0]
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
ddlj1397
  • 1
  • 1

2 Answers2

0

Why not try a function.

def return_vector(letter):
 if letter == ‘A’:
  return [1,0,0,0]
 elif letter == ‘C’:
  return [0,1,0,0]
 elif letter == ‘G’:
  return [0,0,1,0]
 elif letter == ‘T’:
  return [0,0,0,1]
 else:
  return [0,0,0,0]
M. Small
  • 138
  • 5
0

Put the letters in a dictionary, and then use a function to print, assuming that we can pass the letters in as a string;

 d = {'A':[1,0,0,0], 'C': [0,1,0,0], 'G': [0,0,1,0], 'T': [0,0,0,1]}

def my_print(s: str):
    for l in s:
        print(d.get(l,[0,0,0,0]), end = ' ')

my_print('ACGTM')
bn_ln
  • 1,648
  • 1
  • 6
  • 13