Nov-16-2019, 05:37 PM
I am working within a file which is within a for loop. Within this for loop i am wanting to create a new list. I can do what i want using normal list way but was hoping to find out how to convert this into list comprehension. The complication to this is i am wanting to get the length of 'y' within the for loop captured into the new list.
Working way (long way):
I have tried:
Working way (long way):
NewList = [] for (x, y) in file: NewList.append(len(y)) print(NewListThe above gives me what I want. However, I am hoping to make this more elegant and turn this into list comprehension. Anyone any ideas?
I have tried:
Newlist = [item for item in len(y)]However, this does not work :-(. Thanks in advance.