1

I need to create a function that iterates over all sequences of 3 letters (3-mers) in a message. For example, if message = "THE CAT", it should return "THE", "HE ", "E C"," CA", "CAT".

I've tried this code below, but it doesn't give me every permutation:

for i,j,k in zip(message[0::3], message[1::3], message[2::3]):
    return i,j,k
Chris
  • 11
  • 3
  • 1
    I think it's worth mentioning that a `return` inside a `for` loop will only happen once (the first time you get to it: it returns from the function, and no more loop). – e0k Nov 17 '16 at 23:10

1 Answers1

2

You can do

[message[i:i+3] for i in range(len(message)-2)]

(edit: -2)

JulienD
  • 7,102
  • 9
  • 50
  • 84