I want to use list comp' instead of a loop. Let's sat I have a list of lists and I want only the even index elements. Eg: [[a,a], [b,b], [c,c],[g,g]] to..... [[a,a], [c,c]]
This doesn't work
a = [i for i in the_list if i % 2 == 0)]
I want to use list comp' instead of a loop. Let's sat I have a list of lists and I want only the even index elements. Eg: [[a,a], [b,b], [c,c],[g,g]] to..... [[a,a], [c,c]]
This doesn't work
a = [i for i in the_list if i % 2 == 0)]
Here is a possible solution that keeps only lists with even indexes:
result = [lst for i, lst in enumerate(the_list) if i % 2 == 0]