Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.4
- def solution(S, P, Q):
- # write your code in Python 2.7
- ones = []
- twos = []
- threes = []
- fours = []
- sum_ones = sum_twos = sum_threes = sum_fours = 0
- for nucl in S:
- if nucl == 'A':
- sum_ones += 1
- elif nucl == 'C':
- sum_twos += 1
- elif nucl == 'G':
- sum_threes += 1
- elif nucl == 'T':
- sum_fours += 1
- ones.append(sum_ones)
- twos.append(sum_twos)
- threes.append(sum_threes)
- fours.append(sum_fours)
- result = []
- for i in range(len(P)):
- if P[i] == 0:
- a = ones[Q[i]]
- b = twos[Q[i]]
- c = threes[Q[i]]
- d = fours[Q[i]]
- else:
- a = ones[Q[i]] - ones[P[i] - 1]
- b = twos[Q[i]] - twos[P[i] - 1]
- c = threes[Q[i]] - threes[P[i] - 1]
- d = fours[Q[i]] - fours[P[i] - 1]
- if a > 0:
- result.append(1)
- elif b > 0:
- result.append(2)
- elif c > 0:
- result.append(3)
- else:
- result.append(4)
- return result
- S = 'CAGCCTA'
- P = [2, 5, 0]
- Q = [4, 5, 6]
- print(solution(S, P, Q))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement