1

Is there a more efficient way to select items from a raw_list to achieve this

new_list = [raw_list[0][2], raw_list[1][2], raw_list[2][2]]

I was trying to do something like raw_list[:][2], but : could not do what I want.

lanselibai
  • 1,203
  • 2
  • 19
  • 35

1 Answers1

1

it is as simple as looping through the list and getting the item at the position 0:

alist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
newList = []
x=0
while x != len(alist):
    print(alist[x][0])
    newList.append(alist[x][0])
    x = x + 1

This can be done a little more effectively with a for loop, and i suggest you use that, but a while loop is more explanatory.

wondercoll
  • 339
  • 1
  • 4
  • 15