-1

I have list, its elements are also a list. eg:

outlier=[[20,2,67], [90,6,12], [23,16,7]].

how I write a single line code to loop outlier list by taking elements from same index.I want to store the looping result as a list.

Pratik
  • 1,351
  • 1
  • 20
  • 37
lekha
  • 39
  • 6
  • 5
    Did you try yourself? post your code please. – Guy Dec 10 '19 at 11:07
  • 1
    a sample example would be good to know – sahasrara62 Dec 10 '19 at 11:08
  • 2
    What's the expected output? – U13-Forward Dec 10 '19 at 11:08
  • Does this answer your question? [How to access a column in a list of lists in python](https://stackoverflow.com/questions/44360162/how-to-access-a-column-in-a-list-of-lists-in-python) – Georgy Dec 10 '19 at 11:11
  • If I understand correctly you want to loop over the indices of each sublist in turn, i.e. (20, 90, 23) in the 1st loop, (2, 6, 16) in the 2nd and (67, 12, 7) in the 3rd. If this is indeed what you mean, try looking into the built-in `zip`. – Tim Skov Jacobsen Dec 10 '19 at 11:18

1 Answers1

1

The question is not very clear to me, but if you want to make a new list that contains the first element of each list you have, then this is an example to take first element(x[0]) from each list and store them in a new list called "new_list":

new_list = [x[0] for x in outlier]

Meh
  • 188
  • 1
  • 12