1

I know Sorted is the built in function in python and there is a for loop inside the list but what does i doing before 'for'. How would i write this line of code in more detail understandable way. sorted([i for i in range(len(list)) if list[i] != 0])

  • it's an unidiomatic way of doing `sorted([x for x in list if x != 0])` – juanpa.arrivillaga Apr 26 '21 at 20:31
  • 1
    BTW, in general, "please explain this code" questions should show your best-effort attempt at understanding it yourself to avoid being "too broad" -- even with just one line, it's not clear what parts you do and don't know: Do you already know what a list comprehension is? Do you already know what `range()` is/does? Do you already know what `list[i]` is? etc -- trying to show your work at answering it yourself narrows the question and shows more precisely what an answer needs to address. – Charles Duffy Apr 26 '21 at 20:32

0 Answers0