Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 03.12.2005, 15:35   #1
Дошкольник
 
Join Date: 08 2004
Location: Oxford
Age: 38
Posts: 141
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default List capacities in Python

Hey, here I am, again!

A question to the Python experts: is it possible to create a list with a desired capacity? I am not aware about the internal implementation of a Python list, but inserting is very time-consuming, and it looks like a solid array rather than a linked list. Hence, the problem of capacity is crucial for me.
__________________
Она нахмурила свой узенький лобок...
Reply With Quote
Old 05.12.2005, 17:35   #2
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: List capacities in Python

Did you try, e.g.: lst=range(100) ?
Reply With Quote
Old 05.12.2005, 19:50   #3
Дошкольник
 
Join Date: 08 2004
Location: Oxford
Age: 38
Posts: 141
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: List capacities in Python

Quote:
Originally Posted by AvDav
Did you try, e.g.: lst=range(100) ?
You meant range (0, 100)? Yes, I did But than I still have to insert elements in the middle of the list, so even in this case it will cause a memory reallocation (if it's vector-like, as I suppose). In fact, I need an EMPTY list with a big capacity. Anyway, thank you.
Reply With Quote
Old 06.12.2005, 20:26   #4
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: List capacities in Python

Nevertheless, I don't think that the insertion somewhere in the middle even with predefined capacity will be less time-consuming because, most probably, will take linear time. As I understood, the order of elements is significant. I am not quite sure, but seems some sort of hash table would do (dictionary?).
__________________
The main achievements in applied research are due to fundamental science.
Reply With Quote
Old 08.12.2005, 14:58   #5
Дошкольник
 
Join Date: 08 2004
Location: Oxford
Age: 38
Posts: 141
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: List capacities in Python

My problem is that I know nothing about the internal implementation of Python. I can only assume, what lies under the structures. But in fact, the list.sort() ( O(nlogn) ) runs by far faster, than linear search with insertion (O (n)).
Reply With Quote
Old 09.12.2005, 14:41   #6
dardanian
 
aeneas's Avatar
 
Join Date: 11 2005
Location: new troy
Posts: 175
Downloads: 8
Uploads: 0
Reputation: 9 | 0
Default Re: List capacities in Python

Quote:
Originally Posted by Ablertus
My problem is that I know nothing about the internal implementation of Python. I can only assume, what lies under the structures. But in fact, the list.sort() ( O(nlogn) ) runs by far faster, than linear search with insertion (O (n)).
instead of guesses on the internal implementions of python how about posting here some lines from your script or telling about your case more precisely?...
being more practical might be of help
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 09:05.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.