Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeatedly appending to a large list (Python 2.6.6)

Tags:

People also ask

Is appending to a list slow Python?

It does slow down like you claimed. (0.03 seconds for the first iteration, and 0.84 seconds for the last… quite a difference.) Obviously, if you instantiate a list but don't append it to x , it runs way faster and doesn't scale up over time.

Can you append multiple items to a list Python?

extend to extend the list by multiple values from any kind of iterable, being it another list or any other thing that provides a sequence of values. So you can use list. append() to append a single value, and list. extend() to append multiple values.

How do you append to a list in loop?

You can append a list in for loop, Use the list append() method to append elements to a list while iterating over the given list.


I have a project where I am reading in ASCII values from a microcontroller through a serial port (looks like this : AA FF BA 11 43 CF etc) The input is coming in quickly (38 two character sets / second). I'm taking this input and appending it to a running list of all measurements.

After about 5 hours, my list has grown to ~ 855000 entries.

I'm given to understand that the larger a list becomes, the slower list operations become. My intent is to have this test run for 24 hours, which should yield around 3M results.

Is there a more efficient, faster way to append to a list then list.append()?

Thanks Everyone.