shifted zip

Go Back home

It's something useful to compare words in a list.

Given the words:

1 aaa
2 bbb
3 ccc

Compare them as so:

1 aaa < bbb
2 bbb < ccc
3 ccc < ddd

Solution:

1 words = 'aaa bbb ccc ddd'.split()
2 
3 for first, second in zip(words, words[1:]):
4     print(first, '<', second)