list.clear() vs. list = [] ? /u/pachura3 Python Education

Hi, is there a preferred way of clearing a list for further use?

I can imagine that clearing the existing list instead of assigning a new list to the existing variable would save some memory until the next run of garbage collector, but it could maybe lead to memory fragmentation and having less performant container (less performant than a brand new one)? Or maybe I’m reading too much into this and there’s not much difference…

submitted by /u/pachura3
[link] [comments]

​r/learnpython Hi, is there a preferred way of clearing a list for further use? I can imagine that clearing the existing list instead of assigning a new list to the existing variable would save some memory until the next run of garbage collector, but it could maybe lead to memory fragmentation and having less performant container (less performant than a brand new one)? Or maybe I’m reading too much into this and there’s not much difference… submitted by /u/pachura3 [link] [comments] 

Hi, is there a preferred way of clearing a list for further use?

I can imagine that clearing the existing list instead of assigning a new list to the existing variable would save some memory until the next run of garbage collector, but it could maybe lead to memory fragmentation and having less performant container (less performant than a brand new one)? Or maybe I’m reading too much into this and there’s not much difference…

submitted by /u/pachura3
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *