Cody Bable

Generation

generate functionThu, 13 Apr 2023

list comprehension for dividing a list into three lists and reverse the items in the each of the three lists.

def list_comprehension(): a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] b = [i for i in a if i%3 == 0] c = [i for i in a if i%3 == 1] d = [i for i in a if i%3 == 2] b.reverse() c.reverse() d.reverse() return [b, c, d]

Questions about programming?Chat with your personal AI assistant