After a few tries I am not able to convert this for loop into a single line[list comprehension]
print(cells_don[0])
cells_v_don = list()
for cell in cells_don:
row = list()
for i in range(0, len(cell)):
row.append(cell[i].value)
cells_v_don.append(row)
Output: It s just a tuple collecting data from a excel table:
(<Cell 'ede_ser'.C13>, <Cell 'ede_ser'.D13>, <Cell 'ede_ser'.E13>, <Cell 'ede_ser'.F13>, <Cell 'ede_ser'.G13>, <Cell 'ede_ser'.H13>, <Cell 'ede_ser'.I13>, <Cell 'ede_ser'.J13>, <Cell 'ede_ser'.K13>, <Cell 'ede_ser'.L13>, <Cell 'ede_ser'.M13>, <Cell 'ede_ser'.N13>, <Cell 'ede_ser'.O13>, <Cell 'ede_ser'.P13>, <Cell 'ede_ser'.Q13>, <Cell 'ede_ser'.R13>, <Cell 'ede_ser'.S13>, <Cell 'ede_ser'.T13>)
How can I convert this code into a list comprehension?
Thank you!
cells_v_don = [
[cell[i].value for i in range(0, len(cell))]
for cell in cells_don
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.