from more_itertools import chunked, sliced spam = '1a2b3c4d' # without using more_itertools print(dict(zip(spam[::2], spam[1::2]))) # using more_itertools print(dict(chunked(spam, 2))) print(dict(sliced(spam, 2, strict=True)))
Output:{'1': 'a', '2': 'b', '3': 'c', '4': 'd'}
{'1': 'a', '2': 'b', '3': 'c', '4': 'd'}
{'1': 'a', '2': 'b', '3': 'c', '4': 'd'}
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs