How to divide a string into a list of two characters tuples in Python

1 Answer

0 votes
s = "abcdefghijklmnop"
arr_of_two = []

for i in range(1, len(s), 2):
    first = s[i - 1]
    second = s[i]
    arr_of_two.append((first, second))

for pair in arr_of_two:
    print(pair)


'''
run:

('a', 'b')
('c', 'd')
('e', 'f')
('g', 'h')
('i', 'j')
('k', 'l')
('m', 'n')
('o', 'p')

'''

 



answered Nov 1, 2018 by avibootz
...