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):
The 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:
However, this does not work :-(. Thanks in advance.
Working way (long way):
1 2 3 4 5 6 |
NewList = [] for (x, y) in file : NewList.append( len (y)) print (NewList |
I have tried:
1 |
Newlist = [item for item in len (y)] |