Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 7th, 2004, 05:47 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 10
Is there a default size limit to a dictionary, list or array declaration ?

Is there a default size limit to a dictionary, list or array declaration ?
=====================

When I declared a dictionary and a list in Python, there is no where I could specified how big this dictionary or list can be such as declaring an array in C. ex: char array[1000] in C programming.

1) Is there a default size limit to a dictionary, or list declaration in Python (ex: 64 Kb or how many elements) ?

2) Is there a default size limit to an array declaration in Python (ex: 64 Kb or how many elements)?

=====================

dictionary = {'food':{'beef':1, 'egg':2},
'drink':{'apple juice':1, 'grape juice':2}}

list = ['123','456','789']

Reply With Quote
  #2  
Old June 7th, 2004, 07:49 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally Posted by linh
Is there a default size limit to a dictionary, list or array declaration ?
=====================

When I declared a dictionary and a list in Python, there is no where I could specified how big this dictionary or list can be such as declaring an array in C. ex: char array[1000] in C programming.

1) Is there a default size limit to a dictionary, or list declaration in Python (ex: 64 Kb or how many elements) ?

2) Is there a default size limit to an array declaration in Python (ex: 64 Kb or how many elements)?

=====================

dictionary = {'food':{'beef':1, 'egg':2},
'drink':{'apple juice':1, 'grape juice':2}}

list = ['123','456','789']


No, they can be as big as your memory allows. If you need to limit the size, you'll either have to write a wrapper class, or do some size-checking for every addition to the data structure (I recommend the wrapper class approach)
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #3  
Old June 7th, 2004, 08:02 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Python uses dynamic memory allocation so you don't specify the size of an object. It will use as little or as much as you need. Any name can be assigned any object at run time, that object can be dynamically generated (e.g. a complete file read as a string).

It is another example of what makes Python a RAD langauge - it lets you code the solution to the problem - you don't normally have to worry about housekeeping.

If you want to find out how efficiently this is done I guess you will need to read the sources
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #4  
Old June 8th, 2004, 12:26 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
What Grim & strike said. Be aware though that if you are adding elements to a list it has to reallocate the memory as the list grows, which can slow things down. If you know the list is going to reach a certain size eventually you can save processing time by pre-allocating it using [None]*size.

e.g. instead of:

Code:
lst = []
for i in xrange(1000000):
    lst.append('stuff')

you can do:

Code:
lst = [None] * 1000000
for i in xrange(1000000):
  lst[i] = 'stuff'


On my system the first took 2.88 seconds, while the second took 0.75 seconds.

Dave - The Developers' Coach

Last edited by DevCoach : June 8th, 2004 at 01:17 AM. Reason: timings added

Reply With Quote
  #5  
Old June 8th, 2004, 11:39 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 10
Smile reply

Thank you DevCoach for the example.
Thank you Grim Archon and Strike for your answer

Reply With Quote
  #6  
Old June 8th, 2004, 11:47 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 10
reply to DevCoach

Hi DevCoach.
Based on your second example, if a list is predefine with 1,000,000 elements and if it went over that number, then will Python automatically allocate new memory to it or will it crash ?

Reply With Quote
  #7  
Old June 8th, 2004, 12:22 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
Quote:
Originally Posted by linh
Hi DevCoach.
Based on your second example, if a list is predefine with 1,000,000 elements and if it went over that number, then will Python automatically allocate new memory to it or will it crash ?


It will allocate new memory for it.

Dave - The Developers' Coach

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Is there a default size limit to a dictionary, list or array declaration ?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap