Oct-21-2020, 08:21 AM
First problem is that your for loop seems extraneous. You're not using the index variable later.
Your while loop is close, but you're slicing it incorrectly. You want the later value first, you've written
Tweaking it...
Your while loop is close, but you're slicing it incorrectly. You want the later value first, you've written
data[ind+1:ind]
. But since the default step is 1 (a positive number), the slice never works. Better would be to write them as two different accesses: data[ind+1], data[ind]
and combine them.Tweaking it...
import string data = string.ascii_lowercase[:8] ind = 0 while ind < len(data): print("".join(data[ind+1] + data[ind])) ind += 2
Output:ba
dc
fe
hg