Both methods are correct and work. You could probably associate the first path with how everything is done in C and other languages. This means that you basically run the for loop to traverse all the values, and then add it to your list of tuples.
The second method is more pythonic, but does the same. If you look at [(x,y) for x, y, label in data_one] (this is a list comprehension), you will see that you also run a for loop on the same data, but your result will be (x, y) , and all of these results form a list. Thus, he achieves the same.
The third method (added as a comment response) uses the slice method.
I have prepared a small example similar to yours:
data = [(1, 2, 3), (2, 3, 4), (4, 5, 6)] def load_data(): list_of_tuples = [] for x, y, label in data: list_of_tuples.append((x,y)) return list_of_tuples def load_data_2(): return [(x,y) for x, y, label in data] def load_data_3(): return [t[:2] for t in data]
They all do the same and return [(1, 2), (2, 3), (4, 5)] , but their runtime is different. This is why list comprehension is the best way to do this.
When I run the first load_data() method, I get:
%%timeit load_data() 1000000 loops, best of 3: 1.36 µs per loop
When I run the second method load_data_2() , I get:
%%timeit load_data_2() 1000000 loops, best of 3: 969 ns per loop
When I run the third load_data_3() method, I get:
%%timeit load_data_3() 1000000 loops, best of 3: 981 ns per loop
the second way, understanding the list, faster!