Given the following list:
labels = [0, 1, 2, 3, 4]
I wish I could obtain the following by using just one line of code:
['0-1', '1-2', '2-3', '3-4', '4-0']
I can do this with 2 lines of code:
pairwise_labels = [f"{i}-{i+1}" for i in range(len(labels)-1)]
pairwise_labels.append(f"{len(labels)-1}-0")
With just one line, my code will be drastically reduced, as I always need to create an if for the last case to close the loop.
One option would be to use
pairwise(New in version 3.10) :Output :