Cody Bable

Generation

code to explanationThu, 13 Apr 2023

[lst[i:i+3][::-1] for i in range(0, len(lst), 3)]

The code above is a list comprehension that takes every 3 elements from a list and returns a new list where we have reversed the elements in every 3 elements

Questions about programming?Chat with your personal AI assistant