My givens are:
-
a list of N rna sequences (in string form) W = [W0, W1, W2, …, W(n-1)]
-
a list of M queries, Q = [(i, j), (i1, j1), (i2, j2), …, (iN, jN)] (each 0 <= i & each j < N = len(W))
-
if W_i & W_j have different lengths, assume W_i < W_j
Prompt: write a function less_than(W, Q) that returns whether W_i is less than W_j in alphabetical order, for each query
currently, my code is:
def less_than(W, Q):
return [W[i] < W[j] for i, j in Q]
the function calls I have tried with my jupyter notebook so far include:
less_than(
["A", "AA", "AC", "UUG", "AUG", "CGT"],
[(0, 1), (1, 2), (2, 0), (3,4), (5,1), (4, 5), (2,4)],
)
this returned:
[True, True, False, False, False, True, True]
with a time of 946 ns ± 14.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
I have tried searching up ways to further optimize the code, such as seeing if maps or filter would optimize time complexity, but since I still need iteration and alphabetical comparison, I am not sure how I can make the code more efficient.