append – Appending a list to a list of lists using list comprehensions in Python 3.6

بدون دیدگاه

I would be very thankful If you coould help me with this:

I have file and I’m reading and parsing it’s lines. This lines are a list of strings and I’m changing those strings to floats and then, I append that list of floats to another list of lists so my code looks something like this:

for line in file:
    #parsing code...
    [lista_flot.append(float(number)) for number in line]

but I would like to know if there’s a way of appending those lists in a single line with list comprehensions to make it something like this:

for line in file:
    #parsin code...
    lecturas.append([lista_flot.append(float(number)) for number in line])

Also, why when I do that single line all the values turn to Nones?

Thanks a lot!

لینک منبع

  • نویسنده
  • تعداد بازدید
0دیدگاه فرستاده شده است.
شما هم دیدگاه خود را بنویسید